Sending HTTP Requests in Python: Request vs Requests

Feb 3, 2024 ยท 2 min read

When building Python applications that interact with web services, you'll likely need to make HTTP requests to send and receive data. The two most common libraries for making HTTP requests in Python are request and requests. But what's the difference, and which one should you use?

Request - Python's Built-In HTTP Library

Python has a built-in HTTP client library called request that has been around for a long time. To use it, you simply import the request module and call methods like request.get() and request.post() to make HTTP requests.

Here's a quick example:

import request

response = request.get('https://api.example.com/data')
print(response.status_code)
print(response.text)

request is pretty bare bones, but gets the job done for basic HTTP needs.

Requests - A More Powerful Third Party Library

The requests library is a third party module that builds on top of request and provides a simpler, more Pythonic, and more feature-filled interface. Importantly, it abstracts away a lot of lower-level details of making HTTP calls.

Here's how the same request from above looks using requests:

import requests

response = requests.get('https://api.example.com/data')
print(response.status_code)
print(response.text)

Much simpler! requests handles encoding, JSON parsing, cookies, and more for you automatically. And it has great documentation with examples for POST, PUT, DELETE and other methods too.

Conclusion - Use Requests for Most Needs

So in summary, request is a low-level HTTP client that comes built-in with Python, while requests is a very popular third party library that makes HTTP requests easier. For most applications, requests is the easiest way to make web requests. But request can still be useful for advanced cases where you need more control.

Browse by tags:

Browse by language:

The easiest way to do Web Scraping

Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


Try ProxiesAPI for free

curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
...

X

Don't leave just yet!

Enter your email below to claim your free API key: