HTTP Clients

Libraries for working with HTTP.

Requests makes synchronous HTTP calls simple. A Python HTTP client for async code or HTTP/2 means httpx2, whose API stays requests-compatible.

How to choose:

  • Scripts and other synchronous code: Requests
  • One API for sync and async code, or HTTP/2: httpx2
  • Code already on HTTPX: httpx2, the same API under a new name
  • An asyncio app making many requests at once: aiohttp
  • Direct control over connection pools and retries: urllib3
  • Building and editing URLs: yarl

Listed in editorial order, grouped by use case. Click a column header to re-sort the whole list.

Press / to search. Tags open their category. Click a row for details.

Search and filter

Results

Row number Tags

General 5 projects

HTTP Requests for Humans.
psf/github.com/psf/requests /54,564 stars /
Asynchronous HTTP client/server framework for asyncio and Python.
aio-libs/github.com/aio-libs/aiohttp /16,597 stars /
HTTP/1.1 and HTTP/2 client with sync and async APIs, maintained by Pydantic (httpx fork).
pydantic/github.com/pydantic/httpx2 /1,599 stars /
An HTTP library with thread-safe connection pooling, file post, and more.
urllib3/github.com/urllib3/urllib3 /4,082 stars /
A next-generation HTTP client for Python.
encode/github.com/encode/httpx /15,699 stars /

URL Manipulation 1 project

Yet another URL library.
aio-libs/github.com/aio-libs/yarl /1,502 stars /

HTTP Clients guide

Requests is an HTTP library built for human beings, with urllib3 pooling connections underneath. Nearly every call in production code should pass a timeout, since requests never time out unless you set one. For several calls to the same host, make them through a Session used as a context manager: it reuses the TCP connection and closes when the block exits.

httpx2 has a broadly requests-compatible API in both sync and async code, over HTTP/1.1 or HTTP/2. It's a fork of HTTPX with the same public API under a new name. Beyond one-off scripts, send requests through a Client used as a context manager, which pools connections where the top-level functions open a new one per request. In async code, share one AsyncClient instead of opening one inside a loop.

aiohttp is async only, and its docs call that choice a trade of more verbosity for better performance. Create one ClientSession per application and reuse it for every request, since each session holds its own connection pool.

urllib3 is the layer Requests runs on, with thread safety, connection pooling, and retries built in. Make requests through a PoolManager you create: the top-level urllib3.request() uses a module-global one, so its side effects can reach other libraries that call it too.

yarl's URL objects are immutable: every change returns a new URL, and strings you pass in get encoded for you. aiohttp's requests take a yarl URL as well as a plain string.

Know a project that belongs here?

Tell us what it does and why it stands out.