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.
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:
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