Latest Code Tutorials

Python Requests Tutorial With Example | Requests Module


Python Requests Tutorial With Example or Requests Module in Python is today’s topic. Requests is an Apache2 Licensed HTTP library which is written in the Python Programming Language. It is designed to interact with apis. That means you don’t have to manually add the query strings to URLs, or form-encode your POST data. The Requests module is an elegant and simple HTTP library for Python.

If you want to learn more about Python then check out this course Learn Python Programming Masterclass

What is HTTP?

An HTTP is the set of protocols designed to enable the communication between clients and servers. It works as a request-response protocol between a client and the server. The web browser may be the client, and an application on a remote computer that hosts a web site may be the server.

Python Requests Tutorial With Example

Requests allow you to send HTTP requests like GET or POST. You can add the headers, form data, multipart files, and parameters with simple Python dictionaries, and access the response data in the same manner.

How to Install Requests

You can make use of pip, easy_install, or tarball package managers. I am using PIP to install the requests library. I am using Python3, so I have to use pip3 instead of pip.

pip3 install requests


Python Requests Tutorial With Example

Importing the Requests Module

If you want to work with the Requests library in Python, you must import the appropriate module. You can do this only by adding the following code at the beginning of your script. Write the following code inside the file.

import requests

Okay, now let’s send a GET request to the My Github Profile.


import requests

res = requests.get('')
data = res.json()

In the above code, first, we have imported the requests module and then use the GET method to send a GET request to the GitHub api and save the response inside the res variable and then call the json() method on that object and we get the dictionary and then I have called the dictionary by its key and we get the result.


Importing the Requests Module

My Github profile has 311 followers right now, so it has returned the 311. In the future, it might be different depending on when you are taking this tutorial.

When you make the request, Requests makes educated guesses about the encoding of the response based on the HTTP headers.

Other HTTP requests

Till now, we have used the GET request. You can also send the POST, PUT, DELETE, HEAD, and OPTIONS requests.

The syntax for all the request is following.'url')

Finally, Python Requests Tutorial With Example | Requests Module in Python is over.

1 Comment
  1. Romen says

    Thanks for sharing Python Requests Tutorial With Example related full information with us.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.