""" HTTP client management for shared AsyncClient instance. """ import httpx from typing import Optional # Global HTTP client instance _http_client: Optional[httpx.AsyncClient] = None async def init_http_client(): """Initialize the shared HTTP client.""" global _http_client if _http_client is None: _http_client = httpx.AsyncClient( timeout=httpx.Timeout(10.0, connect=5.0), limits=httpx.Limits(max_keepalive_connections=20, max_connections=100) ) async def close_http_client(): """Close the shared HTTP client.""" global _http_client if _http_client: await _http_client.aclose() _http_client = None def get_http_client() -> Optional[httpx.AsyncClient]: """Get the shared HTTP client instance.""" return _http_client