Skip to content

katana_public_api_client.api_wrapper

katana_public_api_client.api_wrapper

Thin CRUD wrappers for all Katana API resources.

Usage::

async with KatanaClient() as client:
    products = await client.api.products.list(is_sellable=True)
    product = await client.api.products.get(123)
    await client.api.products.delete(123)

Classes

ApiNamespace(client)

Dynamic namespace providing client.api.<resource> access.

Resources are created lazily on first attribute access and cached on the instance for subsequent calls. Tab-completion is supported via :meth:__dir__.

Source code in katana_public_api_client/api_wrapper/_namespace.py
def __init__(self, client: AuthenticatedClient) -> None:
    self._client = client

Resource(client, config)

Thin async CRUD wrapper around a single Katana API resource.

Each method delegates to the corresponding generated asyncio_detailed function, unwraps the response, and returns the raw attrs model.

Generated modules are imported lazily on first call and cached for reuse.

Source code in katana_public_api_client/api_wrapper/_resource.py
def __init__(self, client: AuthenticatedClient, config: ResourceConfig) -> None:
    self._client = client
    self._config = config
    self._module_cache: dict[str, ModuleType] = {}
Functions
create(body, **kwargs) async

Create a new resource.

Source code in katana_public_api_client/api_wrapper/_resource.py
async def create(self, body: Any, **kwargs: Any) -> Any:
    """Create a new resource."""
    name = self._require("create", self._config.create)
    mod = self._load_module(name)
    response = await mod.asyncio_detailed(client=self._client, body=body, **kwargs)
    return unwrap(response)
delete(resource_id, **kwargs) async

Delete a resource by ID. Raises on error, returns None.

Source code in katana_public_api_client/api_wrapper/_resource.py
async def delete(self, resource_id: int, **kwargs: Any) -> None:
    """Delete a resource by ID.  Raises on error, returns ``None``."""
    name = self._require("delete", self._config.delete)
    mod = self._load_module(name)
    response = await mod.asyncio_detailed(
        resource_id, client=self._client, **kwargs
    )
    # DELETE endpoints return 204 with parsed=None on success;
    # unwrap() would raise on None, so check status first.
    if not is_success(response):
        unwrap(response)  # raises the appropriate typed error
get(resource_id, **kwargs) async

Fetch a single resource by ID.

Source code in katana_public_api_client/api_wrapper/_resource.py
async def get(self, resource_id: int, **kwargs: Any) -> Any:
    """Fetch a single resource by ID."""
    name = self._require("get", self._config.get_one)
    mod = self._load_module(name)
    response = await mod.asyncio_detailed(
        resource_id, client=self._client, **kwargs
    )
    return unwrap(response)
list(**kwargs) async

Fetch all resources (with optional filters).

Source code in katana_public_api_client/api_wrapper/_resource.py
async def list(self, **kwargs: Any) -> _list[Any]:
    """Fetch all resources (with optional filters)."""
    name = self._require("list", self._config.get_all)
    mod = self._load_module(name)
    response = await mod.asyncio_detailed(client=self._client, **kwargs)
    return unwrap_data(response, default=[])
update(resource_id, body, **kwargs) async

Update an existing resource by ID.

Source code in katana_public_api_client/api_wrapper/_resource.py
async def update(self, resource_id: int, body: Any, **kwargs: Any) -> Any:
    """Update an existing resource by ID."""
    name = self._require("update", self._config.update)
    mod = self._load_module(name)
    response = await mod.asyncio_detailed(
        resource_id, client=self._client, body=body, **kwargs
    )
    return unwrap(response)

ResourceConfig(module, get_one=None, get_all=None, create=None, update=None, delete=None) dataclass

Maps a logical resource to its generated API module functions.

Attributes:

  • module (str) –

    Directory name under api/ (e.g. "product").

  • get_one (str | None) –

    Module name for single-resource GET, or None.

  • get_all (str | None) –

    Module name for list GET, or None.

  • create (str | None) –

    Module name for POST, or None.

  • update (str | None) –

    Module name for PATCH/PUT, or None.

  • delete (str | None) –

    Module name for DELETE, or None.