Files
bruno 2f2a5e9b4a
CI / Lint & Format (push) Failing after 28s
CI / Tests (push) Has been skipped
CI / Security Scan (push) Failing after 8s
CI / Docker Build (push) Has been skipped
Add admin panel, WebSocket support, and API versioning
Introduce an admin portal (React + Nginx), WebSocket routing, and
API versioning middleware with `/api/v1/` prefix deprecation.
Add master API key authentication, new Prometheus metrics for AI
token consumption and active WebSockets, and extend S3 config
with a public endpoint URL. Update test paths and fixtures to
align with the new routing structure.
2026-06-22 11:25:22 -04:00

65 lines
1.8 KiB
Python

"""
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()