# UniServer Python Client

`uniserver-client` is the Python package for calling the UniServer API.

## Install

```bash
pip install uniserver-client
```

## Quick Start

```python
from uniserver import UniServerClient

client = UniServerClient(
    base_url="https://uniserver-hyco.onrender.com",
    account_api_key="uacc_your_account_key"
)

# Create a project (client automatically remembers its first project API key)
project = client.create_project("my-project")
project_id = project["id"]

# KV operations
client.put_kv(project_id, "hello", {"message": "world"})
item = client.get_kv(project_id, "hello")
print(item)

# Object operations
client.put_object(
    project_id,
    item_key="model_cache",
    object_type="CacheBlob",
    serialized={"tokens": [1, 2, 3]},
    encoding="json",
)
print(client.list_objects(project_id))
```

Or with direct package-level functions:

```python
import uniserver

uniserver.configure(
    base_url="https://uniserver-hyco.onrender.com",
    account_api_key="uacc_your_account_key",
)

project = uniserver.create_project("my-project")
project_id = project["id"]

# The first project key is remembered automatically
uniserver.put_kv(project_id, "hello", "world")
print(uniserver.get_kv(project_id, "hello"))
```

## Auth Model

UniServer has two key types:

- Account API key (`X-Uniserver-Account-Key`) for account/project operations.
- Project API key (`X-Project-Api-Key`) for project data operations.

This package stores both in memory:

- Account key: `client.set_account_api_key(...)`
- Project key: `client.set_project_api_key(project_id, ...)`

You can still override per call:

```python
client.list_kv(project_id=4, project_api_key="unis_project_key")
```

## Environment Variables

If you do not pass values in code, the client can read:

- `UNISERVER_BASE_URL`
- `UNISERVER_ACCOUNT_KEY`

## Main Methods

- Health: `health()`
- Accounts: `create_account()`, `get_account()`, `create_account_api_key()`, `delete_account_api_key()`
- Projects: `create_project()`, `list_projects()`, `get_project()`, `update_project()`, `delete_project()`
- Project keys: `create_project_api_key()`, `delete_project_api_key()`
- KV: `list_kv()`, `get_kv()`, `put_kv()`, `delete_kv()`
- Objects: `list_objects()`, `get_object()`, `put_object()`, `delete_object()`

## Build a distributable package

```bash
python -m pip install build
python -m build
```

Built artifacts will be in `dist/`.
