Metadata-Version: 2.5
Name: tetrix-sdk
Version: 0.9.0
Summary: TetrixAIDb Python SDK — AI-native database client
Project-URL: Repository, https://github.com/deskree-inc/tetrix-ee
License-Expression: MIT
Requires-Python: >=3.11
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.9; extra == 'dev'
Description-Content-Type: text/markdown

# TetrixAIDb Python SDK

Async Python client for [TetrixAIDb](https://github.com/deskree-inc/tetrix-ee), the AI-native database daemon that unifies vector, keyword, graph, and object storage behind a single binary protocol.

## Installation

```bash
pip install tetrix-aidb
```

Requires Python 3.11+.

## Quick Start

```python
import asyncio
from tetrix_aidb import ClientConfig, TetrixClient

async def main():
    client = TetrixClient(ClientConfig(
        endpoint="tcp://localhost:7779",
        username="admin",
        password="secret",
    ))
    await client.connect()

    health = await client.health()
    print(f"Status: {health.status}")

    await client.close()

asyncio.run(main())
```

## Features

- Async-first API built on `asyncio`
- TCP, TLS, and Unix socket transports
- Auth-on-connect with automatic session handling
- Entity indexing, semantic search, and batch operations
- IAM operations: organizations, users
- Category management
- Typed request/response models

## Request timeout

`ClientConfig.timeout_ms` (default 30000; `0` = none) bounds every call: waiting for the pooled
connection, connect + AUTH, writing the request and reading the reply. On expiry the call raises
`tetrix_aidb.errors.TimeoutError` (`code="TIMEOUT"`, with `op` and `timeout_ms`; not the builtin
`TimeoutError`):

```python
from tetrix_aidb.errors import TimeoutError as TetrixTimeoutError

try:
    await client.health()
except TetrixTimeoutError as exc:
    print(exc.op, exc.timeout_ms)  # HEALTH 30000
```

The connection is closed, not reused: the daemon answers requests in order, so its late reply
would otherwise be read as the answer to the next request. The same holds when the caller cancels
a request (`asyncio.wait_for`, task cancellation) and for a reply over the 16 MiB read limit (still
`ValueError("frame size N exceeds max M")`). The timeout is not retryable: the daemon may have
applied the request. Before 0.8.0 `timeout_ms` was ignored (tetrix-ee#142), and a cancelled or
oversized reply left the connection out of sync.

## Lean `list_entities` pages (0.9.0)

Each listed item carries its full metadata by default, including `_raw`, the entire source
payload. On a large graph that pushes a page past the 16 MiB response frame. Ask for less
(tetrix-ee#136):

```python
page = await client.list_entities(
    types=["jira_issue"],
    limit=2000,
    exclude_metadata_keys=["_raw"],   # or metadata_keys=["source", "natural_key", ...]
)
```

The daemon drops the keys in SQL; read an item's full metadata with `get`. A page that still
does not fit raises `ResponseTooLargeError` (`code="RESPONSE_TOO_LARGE"`, `details["fitItems"]`,
or `details["entityId"]` for one item too large on its own); the connection stays usable. It
subclasses both `TetrixError` and `ValueError`, and its text is the daemon's
`"response frame size N exceeds max M …"`, so code that caught the old read-side
`ValueError("frame size N exceeds max M")` keeps working. With `allow_truncation=True` the
daemon returns the items that fit instead, with `truncated=True`, `next_cursor`, and
`next_offset`. Continue from those: a truncated page is short but not the last one. The new
arguments are left out of the request when unset, and a daemon without tetrix-ee#136 ignores
them.

## Search legs

Since 0.9.0 `semantic_search()` returns `legs`, which says which legs of the hybrid search ran:
`resp.legs.keyword` and `resp.legs.vector` are each `"ok"` (the leg ran, possibly with zero hits),
`"error"` (it was attempted and failed) or `"skipped"` (it was intentionally not run: no embedding
provider configured, or `SearchOptions(use_keyword=False)`). An empty `items` with both legs
`"ok"` means nothing matched; with a leg at `"error"` it means that leg is down. `legs` is `None`
from a daemon that predates tetrix-ee#135, which also ignores `use_keyword`.

## License

MIT
