Book Image

Python Requests Essentials

By : Rakesh Vidya Chandra, Bala Subrahmanyam Varanasi
Book Image

Python Requests Essentials

By: Rakesh Vidya Chandra, Bala Subrahmanyam Varanasi

Overview of this book

<p>Python is one of the most popular programming languages of our era; the Python Requests library is one of the world's best clients, with the highest number of downloads. It allows hassle-free interactions with web applications using simple procedures.</p> <p>You will be shown how to mock HTTP Requests using HTTPretty, and will learn to interact with social media using Requests. This book will help you to grasp the art of web scraping with the BeautifulSoup and Python Requests libraries, and will then paddle you through Requests impressive ability to interact with APIs. It will empower you with the best practices for seamlessly drawing data from web apps. Last but not least, you will get the chance to polish your skills by implementing a RESTful Web API with Python and Flask!</p>
Table of Contents (15 chapters)
Python Requests Essentials
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Getting started with Flask


We can kick-start our application development with a simple example, which gives you an idea of how we program in Python with a flask framework. In order to write this program, we need to perform the following steps:

  1. Create a WSGI application instance, as every application in Flask needs one to handle requests from the client.

  2. Define a route method which associates a URL and the function which handles it.

  3. Activate the application's server.

Here is an example which follows the preceding steps to make a simple application:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def home():
    return "Hello Guest!"

if __name__ == "__main__":
    app.run()

In the preceding lines of code, we have created a WSGI application instance using the Flask's Flask class, and then we defined a route which maps the path "/" and the view function home to process the request using a Flask's decorator function Flask.route(). Next, we used the app.run() which tells the server...