Metadata-Version: 2.4
Name: zyonix-sdk
Version: 0.1.15
Summary: Zyonix Python SDK: init, run, step, output, feedback
Keywords: zyonix,llm,reliability,observability,tracing,opentelemetry
Author: Zyonix
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: zyonix-model==0.1.15
Requires-Dist: opentelemetry-api>=1.45.2,<2
Requires-Dist: opentelemetry-sdk>=1.45.2,<2
Requires-Dist: opentelemetry-exporter-otlp-proto-common>=1.45.2,<2
Requires-Dist: opentelemetry-proto>=1.45.2,<2
Requires-Dist: httpx>=0.27,<1
Requires-Dist: pyyaml>=6
Requires-Dist: openinference-instrumentation-anthropic>=0.1.20,<1 ; extra == 'anthropic'
Requires-Dist: openinference-instrumentation-bedrock>=0.1.20,<1 ; extra == 'bedrock'
Requires-Dist: openinference-instrumentation-langchain>=0.1.40,<1 ; extra == 'langchain'
Requires-Dist: openinference-instrumentation-litellm>=0.1.20,<1 ; extra == 'litellm'
Requires-Dist: openinference-instrumentation-llama-index>=4.0,<5 ; extra == 'llama-index'
Requires-Dist: openinference-instrumentation-openai>=0.1.30,<1 ; extra == 'openai'
Requires-Dist: openinference-instrumentation-openai-agents>=1.0,<2 ; extra == 'openai-agents'
Requires-Python: >=3.10
Provides-Extra: anthropic
Provides-Extra: bedrock
Provides-Extra: langchain
Provides-Extra: litellm
Provides-Extra: llama-index
Provides-Extra: openai
Provides-Extra: openai-agents
Description-Content-Type: text/markdown

# zyonix-sdk

The Python SDK for [Zyonix](#what-zyonix-is), a reliability layer for AI pipelines that produce
structured results. The SDK records what your pipeline does (one trace per item, one span per
step) and sends it to a Zyonix backend, which checks the results, explains failures and groups
them into issues.

You need a running Zyonix backend, its address, and an `sdk` API key. Python 3.10 or newer.

## Install

```bash
pip install zyonix-sdk                 # the SDK and the `zyonix doctor` / `zyonix init` commands
pip install "zyonix-sdk[openai]"       # + automatic recording of your LLM library's calls
pip install zyonix-cli                 # + the terminal commands that read results
```

If you received the packages as files or from another index, use the install commands that came
with them instead, so that pip does not mix sources.

Extras for LLM libraries: `openai`, `anthropic`, `langchain`, `llama-index`, `litellm`,
`bedrock`. Without one, steps, inputs, outputs and timing are still recorded, but model calls and
token counts are not.

The SDK needs pydantic 2, httpx 0.27+ and OpenTelemetry 1.45+. In an existing environment run
`pip install --dry-run "zyonix-sdk[openai]"` first: pip upgrades older versions without asking.

## Quick start

```python
import zyonix

zyonix.init(service="invoice-extractor", release="2026-10-13-a")  # once, at process start


@zyonix.step("ocr")
def ocr(document: dict) -> str:
    return document["content"]


@zyonix.step("extract", replayable=True)  # exactly one replayable step: the model call
def extract(document_text: str, config: dict) -> dict:
    return {"total": 120.0}  # your model call goes here


@zyonix.run(doc_id=lambda message: message["id"], source="example")  # one trace per item
def process(message: dict) -> dict:
    record = extract(ocr(message), {"model": "my-model"})
    zyonix.output(record, schema="Invoice", schema_version=1)  # the result that is checked
    return record


process({"id": "DOC-1", "content": "Total: 120.00"})
zyonix.flush(10)  # a short script must flush: telemetry is sent in the background
```

## Configuration

`zyonix.init()` reads its settings from the environment, so no secret goes in your code:

| Variable | Meaning |
|---|---|
| `ZYONIX_API_KEY` | an `sdk` key of your Zyonix deployment (without it, tracing is off) |
| `ZYONIX_ENDPOINT` | the `https://` address of the deployment, for example `https://zyonix.dev` |
| `ZYONIX_EGRESS_ALLOW` | its host name, when it is a public name other than `zyonix.dev` |
| `ZYONIX_CA_FILE` | a CA certificate (PEM) to trust for that address, for a private CA |
| `ZYONIX_MODE` | `remote` (default with a key), `local` (write a JSONL file), `console`, `off` |

Arguments to `init()` take precedence over `ZYONIX_*` variables, which take precedence over a
`zyonix.yaml` file (`zyonix init` writes a commented starter). Check a setup with `zyonix doctor`.

## Behaviour you can rely on

- **Fail-open.** The SDK never raises into your code. If the backend is unreachable, your
  pipeline's output is identical and the telemetry is dropped and counted. An exception raised by
  your own code propagates unchanged.
- **Redaction before sending.** E-mail addresses, phone numbers with a country code, IBANs and card
  numbers are masked in your process by default; add your own patterns in `zyonix.yaml`. `capture: hash_only`
  sends content hashes instead of content.
- **Fails closed on content.** Full capture is never a default: content is sent only when a valid
  `zyonix.yaml` says `capture: full` or the code calls `zyonix.init(capture="full")`. No file, or a
  file that does not set `capture`, means hash-only; an invalid file disables tracing until it is
  fixed (`zyonix doctor` says why).
- **Bounded.** Payloads, requests and the in-memory queue are capped in bytes.
- **Beside your OpenTelemetry.** Zyonix keeps its spans on a private tracer provider: your own
  exporters never receive them, unless `otel_provider: shared` says so.

## Public API

`init`, `run`, `step`, `tool`, `output`, `check`, `flag`, `feedback`, `flush`, `shutdown`,
`current_trace_id`, and for runtime repair `guard`, `observe`, `RepairHint`, `GuardHold`,
`GuardReport`, `last_guard_report` (runtime repair needs the detection engine, which is not part
of this package: without it the Guard stays inert and says so once).

- `@zyonix.tool("send_email")`: a function that acts on the world (an API, a database, a
  message). `zyonix test` / `zyonix replay` never run it.
- `zyonix.check("saved", row is not None)` and `zyonix.flag("duplicate", detail)`: problems your
  own code noticed, reported under their own name.
Anything whose name starts with an underscore is internal and may change.

## What Zyonix is

A closed loop around AI pipelines: observe, detect failures with deterministic checks, diagnose
a root cause, verify a fix on recorded cases, and monitor for recurrence. This package is the
client side only; the backend is deployed separately.
