Python HTTPX2: Reusable Clients, Async Requests, and HTTP/2
- William Martinez
- 780 reads
HTTPX2 keeps HTTPX’s familiar API while adding a maintained path forward, connection pooling, async support, timeouts, and HTTP/2.

HTTPX2’s practical appeal is that Python teams can keep a familiar HTTP request interface while gaining tools for connection reuse, concurrent I/O, and HTTP/2. For scripts that make a handful of calls, the change may be small. Services that talk to many APIs, handle slow responses, or need predictable failure behavior have more to gain.

What HTTPX2 changes for existing HTTPX users
HTTPX2 is a fork of Python’s HTTPX, with Pydantic taking stewardship of the project in 2026. The two are separate packages: they have different installation names and imports, and can be installed together in one environment. HTTPX2 retains the public API, so much existing HTTPX code can carry over with few or no code changes.
There are a few migration details to account for. The command-line tool and the underlying httpcore package have new names, support for Python 3.9 has ended, and TLS certificate verification now relies on the operating system’s trust store rather than a bundled certificate list. That trust-store choice can simplify work behind a corporate proxy that inspects encrypted traffic, provided the organization’s root certificate is installed on the machine.
Requests remains a useful reference point for the API style, but HTTPX2 is designed to cover both synchronous and asynchronous programs. That lets a team use one library across small scripts and workloads with many concurrent network operations, instead of adopting a separate client solely for async code.
Start with a one-off request, then reuse connections
A basic GET request looks much like it does in other Python HTTP clients:
import httpx2
response = httpx2.get("https://api.github.com/events")
print(response.status_code)
print(response.json())The top-level get() function is convenient for isolated requests. When code makes several requests, a reusable Client is a better fit. It can keep connections open and pool them for subsequent calls, avoiding the cost of setting up a fresh connection every time. The client also provides a place to share configuration across requests, which is useful when a program repeatedly calls the same service or needs consistent headers and settings.
Connection pooling matters most when requests happen in a sequence or in a long-running process. It can reduce repeated setup work, though the benefit depends on the service, network, and request pattern. A client should be managed with a context manager so its connections are closed when the work is done.
Use async when waiting dominates the workload
For programs that need to make multiple network calls without waiting for each one to finish before starting the next, HTTPX2 offers AsyncClient. It works with Python’s asyncio model. The client’s request methods are awaited, allowing the event loop to run other tasks while a response is pending.
This is useful when a program spends much of its time waiting on remote servers: for example, gathering data from several endpoints or handling many independent API calls. Async does not make an individual server respond faster, and it adds coordination requirements to the application. Code that uses it needs an async entry point and must await the relevant calls. For a short script with only one request, synchronous code is usually simpler.
Using one AsyncClient for a group of requests also allows connection reuse within that asynchronous workload. As with the synchronous client, its lifetime should be scoped so the connections are closed cleanly.
Timeouts and exceptions make failures manageable
A request can stall because a server is slow, a connection cannot be established, or data stops arriving. HTTPX2 supplies sensible default timeouts, and its granular timeout controls let a caller tune how long different stages of a request may take. That makes it possible to set behavior that matches an application’s needs rather than letting network waits run indefinitely.
Failure handling is also easier to organize when code can catch exceptions from a clear hierarchy. A caller can handle broad request failures in one place or respond differently to more specific problems. The right choice depends on what the application can recover from: retrying a transient connection failure may make sense, while repeatedly retrying a malformed request generally won’t.
Stream large responses and opt into HTTP/2
When a response is large, loading the entire body into memory before processing it can be wasteful. HTTPX2 supports streaming, so code can consume response data in chunks and process it as it arrives. This is a practical option for downloads or other large payloads, where keeping memory use bounded matters. The application still needs to close the response or use the appropriate context manager to release resources.
HTTP/2 support is another available capability. Enabling it requires an additional dependency and a client configuration argument. That small setup cost may be worthwhile when the remote service supports HTTP/2 and the workload can benefit from the protocol. The source material does not provide benchmark results, so teams should measure their own request patterns rather than assume a performance gain.
What to check before migrating
For a Requests user, the first request may feel familiar, but the larger decision is whether the application can benefit from shared clients, async I/O, streaming, or HTTP/2. Existing HTTPX users have a more direct path because the public API is retained, though Python version support, renamed components, and TLS trust behavior still deserve review.
HTTPX2 is available as version 2.13.1 in the installation example, alongside Requests 2.34.2, and the tutorial targets Python 3.10 or newer. Teams evaluating it should first test the behavior that matters in their environment: certificate trust behind proxies, timeout handling against slow services, and connection reuse under their actual workload. Those checks will show whether the fork’s maintenance path and protocol options deliver enough practical value to justify a change.