33import asyncio
44import atexit
55import threading
6- from collections .abc import AsyncIterator
6+ from collections .abc import AsyncIterator , Mapping
77from contextlib import asynccontextmanager
8- from typing import Any
98
109import httpx
1110
1211from .config import get_config
12+ from .exceptions import ConfigurationError
1313from .transport import httpx_client_factory
1414
1515# global client pool keyed by config
1616_clients : dict [tuple [str , str ], httpx .AsyncClient ] = {}
1717_lock = threading .Lock ()
1818
1919
20- def _make_client_key (config : dict [str , Any ]) -> tuple [str , str ]:
20+ def _make_client_key (config : Mapping [str , str | None ]) -> tuple [str , str ]:
2121 """Generate a unique key for client pooling based on config."""
2222 base_url = config .get ("data_api_root_url" ) or ""
2323 api_key = config .get ("api_key" ) or ""
@@ -39,10 +39,10 @@ def get_client() -> httpx.AsyncClient:
3939 if key not in _clients :
4040 base_url = config .get ("data_api_root_url" )
4141 if not base_url :
42- raise RuntimeError ("data_api_root_url" )
42+ raise ConfigurationError ("data_api_root_url" )
4343 api_key = config .get ("api_key" )
4444 if not api_key :
45- raise RuntimeError ("api_key" )
45+ raise ConfigurationError ("api_key" )
4646 _clients [key ] = httpx_client_factory (base_url = base_url , api_key = api_key )
4747 return _clients [key ]
4848
0 commit comments