""" Main client for the Imago SDK. """ from typing import Optional, Any import httpx from .resources.images import ImagesResource from .resources.ai import AIResource from .resources.auth import AuthResource class HubClient: """ Main asynchronous client for interacting with the Imago backend API. Example: async with HubClient("http://localhost:8000", api_key="my-key") as client: image = await client.images.get(1) """ def __init__( self, base_url: str, api_key: Optional[str] = None, timeout: float = 30.0, **kwargs: Any ): """ Initializes the HubClient. Args: base_url: The root URL of the Imago API. api_key: The X-API-Key used for authentication. timeout: Default timeout for requests. kwargs: Additional arguments passed to httpx.AsyncClient. """ self.base_url = base_url.rstrip('/') self.api_key = api_key headers = kwargs.pop("headers", {}) if api_key: headers["X-API-Key"] = api_key self._http_client = httpx.AsyncClient( base_url=self.base_url, headers=headers, timeout=timeout, **kwargs ) # Initialize resources self.images = ImagesResource(self._http_client) self.ai = AIResource(self._http_client) self.auth = AuthResource(self._http_client) async def __aenter__(self) -> "HubClient": await self._http_client.__aenter__() return self async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: await self._http_client.__aexit__(exc_type, exc_val, exc_tb) async def close(self) -> None: """Closes the underlying HTTP client.""" await self._http_client.aclose()