Requests Module

Published Sep 14, 2022Updated Apr 2, 2023
Contribute to Docs

The requests module is the de facto standard for sending HTTP requests in Python.

It abstracts the complexities of making requests behind an API so that code can focus on interacting with services and consuming data in the application.

The HTTP request returns a Response Object with all the response data (content, encoding, status, etc).

Installation

Installing the requests module is done by running the following pip command in the terminal:

pip install requests

Or for Python 3:

pip3 install requests

Once requests is installed, it can be used in a program and imported like this:

import requests

Requests Module

.delete()
Sends a DELETE request to a web server and returns a response object.
.get()
Sends a GET request to a web server and it returns a response object.
.head()
Sends a HEAD request to a web server and it returns a response object.
.post()
Sends a POST request to a web server and returns a response object.
.put()
Sends a PUT request to a web server and returns a response object.
.request()
Sends seven main kinds of request to a web server: get, options, head, post, put, patch, and delete; it can also handle custom HTTP verbs if needed, and returns a response object.

All contributors

Looking to contribute?

Learn Python on Codecademy