Does Python requests use urllib3?

Feb 20, 2024 ยท 2 min read

The Python requests library is one of the most popular ways to make HTTP requests in Python. Under the hood, requests relies on urllib3 to handle many aspects of making HTTP requests and handling responses. So what exactly is the relationship between requests and urllib3?

Requests is a Wrapper Around urllib3

The requests library provides an elegant, simple API for making HTTP requests in Python. When you call methods like requests.get() or requests.post(), requests handles:

  • Encoding parameters
  • Handling headers
  • Parsing responses
  • Managing cookies
  • But under the hood, requests delegates the actual network request and response handling to urllib3. So urllib3 handles:

  • Opening sockets
  • Managing connections
  • Sending/receiving data
  • SSL/TLS encryption
  • So in essence, requests provides a nice high-level interface, while urllib3 handles the low-level details of making network requests. requests wraps urllib3 to make it simpler to work with.

    Why Use Requests Instead of urllib3 Directly?

    Since requests builds on top of urllib3, why not just use urllib3 directly? There are a few reasons:

  • requests provides a much simpler and more intuitive API than urllib3.
  • requests handles encoding parameters, handling cookies, and parsing responses for you automatically.
  • requests integrates well with other Python libraries and tools.
  • So in most cases, requests is the best choice for making HTTP requests. But urllib3 is still useful for advanced, low-level use cases.

    Key Takeaways

  • requests is one of the most popular Python libraries for making HTTP requests
  • Under the hood, requests uses urllib3 to handle opening connections and transferring data
  • requests wraps urllib3 with a simpler, higher-level interface
  • For most tasks, requests is preferable to using urllib3 directly
  • So in summary, requests builds on urllib3 to provide a great high-level interface for making HTTP requests in Python.

    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: