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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours