A person pushing a cart of crates labeled Requests into a large machine labeled HTTPX, which has an All Clear sign, a code screen, and a Python chip.

Python HTTPX: Making HTTP Requests With HTTPX2

by Cléa Aumont Updated Reading time estimate 26m intermediate best-practices

If you’ve used Requests, then you’ve probably felt its limits the moment you needed to fire off a batch of API calls at once or keep one stalled server from freezing your script. HTTPX2, the Pydantic-maintained fork of Python HTTPX, keeps the Requests-style API you know while adding asynchronous requests, sensible default timeouts, and HTTP/2. In this tutorial, you’ll learn how to move from Requests to HTTPX2.

By the end of this tutorial, you’ll understand that:

  • A reusable Client pools connections instead of opening a new one per request.
  • AsyncClient handles concurrent requests with asyncio.
  • Granular timeouts and a clear exception hierarchy make failures predictable.
  • Streaming processes large responses without ever loading them fully into memory.
  • HTTP/2 costs one extra dependency and one argument.

To get the most out of this tutorial, you should be comfortable making basic requests with Requests and working with dictionaries, with statements, and exceptions. You don’t need prior experience with