Metadata-Version: 2.4
Name: kailash-client
Version: 0.9.6
Summary: Kailash test-resource service Python client (full codegen: apis+models+runtime, plus wrapper facade)
Author: Yiting Qiang
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.7
Requires-Dist: python-dateutil>=2.8
Requires-Dist: typing-extensions>=4.8
Requires-Dist: urllib3>=2.0
Dynamic: license-file

# kailash-client (Python)

Python client for [kailash](https://github.com/qiangyt/kailash) — a test-resource
control plane that hands out isolated, short-lived infrastructure resources
(PostgreSQL schemas, Elasticsearch indices, Redis databases, MinIO buckets,
Hatchet tenants, MySQL databases, Chrome contexts) as *slots* acquired from a
pool of registered instances.

The package ships two layers:

- a fully generated API/client layer (`kailash_client.generated`, pydantic v2
  models plus one typed API class per kailash endpoint), and
- a thin hand-written facade, `KailashClient`, which is the recommended entry
  point.

## Installation

```bash
pip install kailash-client
```

Requires Python 3.10+.

## Quickstart

Point the client at a running kailash server (`http://localhost:18080` is the
default) and acquire a slot from the zero-dependency in-memory `demo` category
(note: `demo` is disabled by default on a stock deployment — a ROOT user can
enable it via `POST /api/categories/demo/enable`):

```python
from kailash_client import AcquireRequest, KailashClient, Slot, SlotSpec
from kailash_client.generated.models import DemoSlotSpec

client = KailashClient("http://localhost:18080", auth=("user", "password"))

slot: Slot = client.slots.acquire(
    AcquireRequest(
        spec=SlotSpec(
            DemoSlotSpec(
                caller_app="my-app",
                caller_run="run-1",
                timeout_seconds=600,
            )
        )
    )
)
print(slot.slot_id, slot.endpoint)

# Release as soon as you are done — the TTL is only a safety net.
client.slots.release(slot.slot_id)
```

`SlotSpec(...)` wraps one concrete spec (polymorphic oneOf); every category has
its own spec model, e.g. `PgSlotSpec`, `RedisSlotSpec`, `EsSlotSpec`.

## Authentication

kailash requires authentication on all `/api/*` endpoints (Basic or Bearer):

- `KailashClient(base_url, auth=(username, password))` sends HTTP Basic on
  every request.
- `client.login(username, password)` exchanges the credentials for a Bearer
  token (TTL 12h on the server) and uses it for subsequent requests;
  `client.logout()` revokes it and falls back to Basic (or clears the header
  if no Basic credentials were given).

## Error handling

Server errors can be normalized to a structured triple (`status`, `message`,
`message_key`) for i18n/branching:

```python
from kailash_client import KailashApiError
from kailash_client.generated.exceptions import ApiException

try:
    client.slots.acquire(request)
except ApiException as e:
    err = KailashApiError.from_api_exception(e)
    print(err.status, err.message, err.message_key)
```

## Timeouts and retries

The client does not impose its own timeouts or automatic retries — pass
`_request_timeout=...` per call or configure the urllib3 pool on the generated
`Configuration`. See the
[main README](https://github.com/qiangyt/kailash) for the full auth model,
error contract, and plugin/category documentation.

## Other clients

The same API is available as
[Java](https://github.com/qiangyt/kailash/tree/main/clients/kailash-client-java),
[TypeScript](https://github.com/qiangyt/kailash/tree/main/clients/kailash-client-typescript),
[JavaScript](https://github.com/qiangyt/kailash/tree/main/clients/kailash-client-javascript),
[Rust](https://github.com/qiangyt/kailash/tree/main/clients/kailash-client-rust), and
[Go](https://github.com/qiangyt/kailash/tree/main/clients/kailash-client-go) clients.
