Skip to main content

HTTPX

HTTPX is a full-featured Python HTTP client library with both synchronous and asynchronous APIs. It is often treated as the modern alternative to requests.

Features

  • Sync and async APIs: one consistent interface for both styles
  • HTTP/2 support: better performance where supported
  • Connection pooling: automatic connection reuse
  • Timeout control: fine-grained timeout settings
  • Type hints: complete type annotations

Installation

Synchronous requests

Basic usage

Using Client

Asynchronous requests

Basic usage

Concurrent requests

Advanced features

Timeout settings

Authentication

File uploads

Streaming downloads

Proxy settings

Retry handling

Response handling

Compared with requests

Best practices

  1. Reuse connections with Client for better performance.
  2. Set sensible timeouts to avoid hanging requests.
  3. Prefer async in high-concurrency scenarios.
  4. Handle errors explicitly and retry where appropriate.

References

Last modified on April 19, 2026