How it works · Python library for calling the web

How Requests works

One friendly line, requests.get(url), on top of the fiddly work of opening connections and speaking HTTP.

Think of it like this. A travel agent: you say where you want to go, and they handle the tickets, the transfers and the return trip.

  1. The API get, post, put, delete: the one-liners you call. src/requests/api.py
  2. The session Remembers cookies and settings between calls, and follows redirects. src/requests/sessions.py
  3. Request and response Builds the exact bytes to send, and wraps what comes back as .text, .json() and .status_code. src/requests/models.py
  4. Adapters Hands the prepared request to urllib3, which owns the real connections. src/requests/adapters.py
  5. Auth and cookies Adds a login to a request, and keeps the cookies a site sets. src/requests/auth.py

Follow one thing through: requests.get("https://example.com")

  1. get() opens a temporary session and asks it to make the request.src/requests/api.py
  2. The session merges in its own cookies, headers and settings.src/requests/sessions.py
  3. The request is prepared: the address is encoded and the headers and body are made final.src/requests/models.py
  4. The session picks the adapter registered for “https://”.src/requests/sessions.py
  5. The adapter passes it to urllib3, which opens a connection (or reuses one) and sends it.src/requests/adapters.py
  6. The reply is wrapped as a Response. If it says “go elsewhere”, the session follows.src/requests/sessions.py

The clever bit: Adapters, chosen by how the address starts

A session keeps a small table: addresses starting with https:// use this adapter, http:// that one. You can mount your own on any prefix, so calls to one site get extra retries, or a test can answer without touching the network. The longest matching prefix wins.

src/requests/sessions.py

Words you’ll meet

session
A set of calls that share cookies, settings and open connections.
prepared request
The request exactly as it will be sent, byte for byte.
connection pool
Open connections kept ready, so the next call to the same site skips the setup.
redirect
A reply that says “what you want is at this other address”.

Good questions to ask next

Open Requests in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.

Take Requests apart yourself.

Free and open source. Nothing to install, no account.

Ideas inside it

More projects, taken apart

Written by hand from the code as it was on 2026-12-03 (commit 76dfda3). Requests belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.