Requests is an Apache2 Licensed HTTP library, written in Python. It is designed to be used by humans to interact with the language. This means you don%u2019t have to manually add query strings to URLs, or form-encode your POST data. Don%u2019t worry if that made no sense to you. It will in due time.
What can Requests do?
Requests will allow you to send HTTP/1.1 requests using Python. With it, you can add content like headers, form data, multipart files, and parameters via simple Python libraries. It also allows you to access the response data of Python in the same way.
In programming, a library is a collection or pre-configured selection of routines, functions, and operations that a program can use. These elements are often referred to as modules, and stored in object format.
Libraries are important, because you load a module and take advantage of everything it offers without explicitly linking to every program that relies on them. They are truly standalone, so you can build your own programs with them and yet they remain separate from other programs.
Think of modules as a sort of code template.
To reiterate, Requests is a Python library.
How to Install Requests
The good news is that there are a few ways to install the Requests library. To see the full list of options at your disposal, you can view the official install documentation for Requests here.
You can make use of pip, easy_install, or tarball.
If you'd rather work with source code, you can get that on GitHub, as well.
For the purpose of this guide, we are going to use pip to install the library.
In your Python interpreter, type the following:
pip install requests
Importing the Requests Module
To work with the Requests library in Python, you must import the appropriate module. You can do this simply by adding the following code at the beginning of your script:
import requests
Making a Request
When you ping a website or portal for information this is called making a request. That is exactly what the Requests library has been designed to do.
To get a webpage you would do something like the following:
r = requests.get(%u2018https://github.com/timeline.json%u2019)
Comments