httpx for HTTP requests. However, for improved concurrency performance you can use aiohttp as the HTTP backend.
Installation
First, install the SDK with theaiohttp extra:
Basic usage
Enable aiohttp by instantiating the client withhttp_client=DefaultAioHttpClient():
Why use aiohttp?
aiohttp can provide better concurrency performance compared to httpx in certain scenarios, particularly when:
- Making many concurrent requests
- Working with high-throughput applications
- Needing fine-grained control over connection pooling
Using with context manager
Always useDefaultAioHttpClient with the async with context manager to ensure proper resource cleanup:
Compatibility
DefaultAioHttpClient preserves the same defaults that the SDK uses internally:
- Default timeout of 60 seconds
- Default connection limits
- Automatic redirect following