← ClaudeAtlas

async-http-patternslisted

Async HTTP client patterns for Python — httpx, aiohttp, retry strategies, connection pooling, streaming, and testing with respx.
Izangi2714/claude-code-python-stack · ★ 0 · Data & Documents · score 65
Install: claude install-skill Izangi2714/claude-code-python-stack
# Async HTTP Client Patterns Patterns for making HTTP requests in async Python applications. ## When to Activate - Making HTTP requests to external APIs - Implementing API clients/wrappers - Handling retries and timeouts - Streaming large responses - Testing HTTP interactions ## httpx (Recommended) ### Basic Usage ```python import httpx # Sync response = httpx.get("https://api.example.com/users") response.raise_for_status() data = response.json() # Async async with httpx.AsyncClient() as client: response = await client.get("https://api.example.com/users") response.raise_for_status() data = response.json() ``` ### Reusable Client with Connection Pooling ```python import httpx from contextlib import asynccontextmanager class APIClient: def __init__(self, base_url: str, api_key: str): self.client = httpx.AsyncClient( base_url=base_url, headers={"Authorization": f"Bearer {api_key}"}, timeout=httpx.Timeout(30.0, connect=5.0), limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), ) async def get_user(self, user_id: int) -> dict: response = await self.client.get(f"/users/{user_id}") response.raise_for_status() return response.json() async def create_user(self, data: dict) -> dict: response = await self.client.post("/users", json=data) response.raise_for_status() return response.json() async def close(self):