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
Cookie management
Proxy settings
Retry handling
Response handling
Compared with requests
Best practices
- Reuse connections with
Client for better performance.
- Set sensible timeouts to avoid hanging requests.
- Prefer async in high-concurrency scenarios.
- Handle errors explicitly and retry where appropriate.
References
Last modified on April 19, 2026