Skip to main content

yitrace-db

Embedded yiTrace DB for Python agents.

yitrace-db is the Python equivalent of @yitrace/db: it embeds the Rust yiTrace engine in the Python process and calls EngineJsonApi in-process. It does not parse yiTrace files in Python and does not send embedded calls through a TCP socket. It can optionally expose the same DB through FastAPI or the yitrace-db serve CLI when you want a local server.

Install

For local development from this repository:

cd yitrace-db-python
python -m pip install -e .

Public wheels should be built with maturin per platform:

cd yitrace-db-python
python -m pip install maturin
python -m maturin build --release --interpreter "$(command -v python)"

Use --interpreter when the machine has multiple Python installs; otherwise maturin may discover an old system Python instead of the environment you are building for.

Test

python -m pytest

From the repository root, run the package-mode eval when changing package contracts, connect(path=...), FastAPI router behavior, or server-mode docs:

./scripts/package_mode_eval.sh

Usage

You can use it directly:

from yitrace_db import YiTraceDB, create_span_event_builder

db = YiTraceDB.open("./data", tenant_id=1)

events = create_span_event_builder({
    "trace_id": "run-uuid",
    "session_id": "session-uuid",
    "attrs": {
        "project_id": "agentic-data",
        "skill": "review",
        "mode": "auto",
    },
})

events.start_span(span_id="span-uuid", name="risk review", input_text="疑似盗刷")
events.log("疑似盗刷", span_id="span-uuid")
events.end_span(span_id="span-uuid", status=0, duration_ns=12_000_000, output_text="needs review")
events.ingest(db)

hits = db.search({"text": "盗刷", "k": 10, "filter": {"attrs": {"project_id": "agentic-data"}}})
span = db.span("run-uuid", "span-uuid")

trajectories = db.trace_trajectories({
    "filter": {"projectId": "agentic-data", "taskFingerprint": "refund-v1"}
})
groups = db.trajectory_groups({
    "filter": {"projectId": "agentic-data", "taskFingerprint": "refund-v1"}
})
diff = db.trace_diff("run-a", "run-b")
loops = db.loops(projectId="agentic-data", taskFingerprint="refund-v1")
task_runs = db.task_traces("refund-v1", validationStatus="pass")

annotation = db.annotate(
    traceId="run-uuid",
    spanId="span-uuid",
    label="best_path",
    score=950,
    source="human",
    attrs={"project_id": "agentic-data", "skill": "review"},
)
db.update_annotation(annotation["annotationId"], status="resolved", reviewer="qa")
db.link_dataset_item(
    datasetId="agentic-regression",
    itemId="case-1",
    traceId="run-uuid",
    spanId="span-uuid",
    split="eval",
    label="pass",
)

plan = db.retention_plan(
    {
        "filter": {"projectId": "agentic-data"},
        "deleteBeforeTs": 100000,
        "protect": {"annotations": True, "datasetAssociations": True},
    }
)
result = db.apply_retention(
    {
        "filter": {"projectId": "agentic-data"},
        "deleteBeforeTs": 100000,
        "requestedBy": "nightly-retention",
    }
)
audits = db.retention_audits(source="nightly-retention")

db.close()

Use with to close safely:

with YiTraceDB.open("./data", tenant_id=1) as db:
    print(db.search(text="盗刷", k=10))

Use db.lock_metrics() when a service feels slow around embedded writes. It returns whether embedded locking is enabled, lock acquire counts, wait counts, active waiters, wait milliseconds, timeout counts, stale lock cleanup counts, and reader pin counts.

Or through the user-facing yitrace package:

python -m pip install "yitrace[db]"
# Or install the two packages explicitly:
python -m pip install yitrace yitrace-db
from yitrace import DbExporter, Tracer, connect

db = connect(path="./data", tenant_id=1)
tracer = Tracer(exporter=DbExporter(db, tenant_id=1), node_id=1)

The existing yitrace package remains the pure-Python instrumentation SDK and client facade. Use yitrace when you want one import for HTTP and local modes. Use yitrace-db directly when a Python app needs the embedded DB handle.

Server Mode

Install optional server dependencies:

python -m pip install "yitrace-db[server]"

Expose an embedded DB through FastAPI:

from fastapi import FastAPI
from yitrace_db import YiTraceDB
from yitrace_db.fastapi import create_yitrace_router

db = YiTraceDB.open("./data", tenant_id=1)
app = FastAPI()
app.include_router(create_yitrace_router(db), prefix="/yitrace")

Or start the small CLI server:

yitrace-db serve --data-dir ./data --bind 0.0.0.0:7878

Embedded mode can be used by multiple local worker processes. Each worker may call YiTraceDB.open("./data"); the Rust engine serializes open/write paths inside the data dir. Before each write it refreshes WAL, manifest, and metadata: an unchanged WAL is skipped, an appended WAL is applied from its tail, and derived indexes are rebuilt only when the manifest changes. Cross-process reader pins stop reclaim() from physically deleting segment files while another process still holds a snapshot. Do not share one data directory across machines or unreliable network filesystems. For multi-host deployments, run one yiTrace server process and send workers to it over HTTP.

The read-model helpers above are single-node implementations. Common filters such as project_id, skill, task_fingerprint, loop_id, validation_status, tool_name, and model use the attrs sidecar postings and return readPlan. Postings are memory-budgeted: very wide values or total-entry pressure disable only the affected postings, then queries fall back to the sidecar rows and still return correct results. Persistent data dirs write a disposable filter_attrs.dat segment cache; reopen loads it before replaying the WAL tail, and stale or corrupt cache contents are rebuilt from the current snapshot. No-text trace_aggregate() can use the in-memory aggregate rollup (readPlan.source == "aggregate_rollup"). Persistent data dirs also write a disposable trace_rollup.dat segment cache; reopen loads it before replaying the WAL tail, and stale or corrupt cache contents are rebuilt from the current snapshot. Deletes, retention apply, and segment upgrades rebuild the cache as well. Trajectory, loop, and task helpers can return readPlan.source == "trajectory_rollup" for no-text path summaries and reuse the same trace_rollup.dat cache after reopen. When those helpers expand complete traces after finding candidates, readPlan.traceFetchSource shows whether that second step also used the rollup by trace id. Text filters still use the normal folded read path. Disk sidecars and dedicated trajectory-loop-task indexes can be added later without changing these method names.

Annotation and dataset association use the same embedded metadata ledger as Node/Rust. They keep review and regression-set links beside trace data without copying large trace payloads.

Retention audit and policy records are stored in that same ledger. Retention is always explicit: dry-run with retention_plan(), then call apply_retention() or trigger saved policies with run_retention_policies(). Audit and policy queries use the same in-memory metadata postings as annotations.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

yitrace_db-0.1.6-cp38-abi3-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

yitrace_db-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

yitrace_db-0.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

yitrace_db-0.1.6-cp38-abi3-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

yitrace_db-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file yitrace_db-0.1.6-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: yitrace_db-0.1.6-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for yitrace_db-0.1.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3361da38a466b6aa33d76dc93d04ea5b25120c1e7d8c264fb05e28fdd337d0d2
MD5 18704731d73b94e41dc1eded4c2fd427
BLAKE2b-256 4af0967f1e1033e7f9bc3714e74bed0ff471644dee08ba60cde16915ecd951a9

See more details on using hashes here.

File details

Details for the file yitrace_db-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yitrace_db-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5fb8cf1f36b6c3f9691527a4ea3071b460c77b27f60d5d8c5e058c28de37af8d
MD5 9f90786ffdb372e84f598dc787689e67
BLAKE2b-256 d95ae0757ab782c53196d8fb86758afd40ec5308b9ae9e00ad79c8a6daeb7d4e

See more details on using hashes here.

File details

Details for the file yitrace_db-0.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for yitrace_db-0.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ecf5d3107e45feb36cf299a0c37f91ee77a52a93b8459b822c666be80b64b8a8
MD5 0b4fc4db30af3e070336e1bd29890ffa
BLAKE2b-256 f1992b92a4d7c7a76db953ff1778bd59d900efdbdbe4eaf0c3bab36c43c9b3a7

See more details on using hashes here.

File details

Details for the file yitrace_db-0.1.6-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for yitrace_db-0.1.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55b71124c146a120bfa8e1b81992ffe5ef66bc273d08edbb603316c0f078f3b5
MD5 a102e9105db1ce7acb31c2f531337760
BLAKE2b-256 7f46f4be1492e06b58290703c19638e4dc7d5fddba8e78f6bf8a035a72fe609a

See more details on using hashes here.

File details

Details for the file yitrace_db-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for yitrace_db-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6d33df92a00d0ea880f95132a51230d04ad8baa0e0c29175d34f3a86e14b0d75
MD5 bce1ad5c40cb29e2e30fef3fd31aea8e
BLAKE2b-256 f11bfbbdbd664b9ff295998b6bc60cd5de5e7c26dc83429a84b060f2786d9325

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.8

5 files

0.1.7

5 files

This release

0.1.6 This release

5 files

0.1.5

5 files

0.1.4

5 files

0.1.3

5 files

0.1.0

5 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page