Skip to main content

stratadb — Strata for Python

The Python SDK for Strata: an embedded multi-model database for AI agents. SQLite-shaped, not a server — it links the engine in process and opens a file-backed (or in-memory) database directly.

Five primitives — key-value, JSON documents, vectors, an event log, and a graph — share one branch-aware, time-travelling storage substrate. The SDK speaks the exact same command surface, value shapes, and error codes as the strata CLI and MCP server, so learning one channel is learning all of them.

For coding agents — start here

Install with uv add stratadb (or pip install stratadb), then call stratadb.agents_guide() first. It returns the complete offline Python usage guide (every namespace, db.ai, provider keys, branches / time-travel, errors — all runnable Python), so you can learn the whole surface without probing it:

import stratadb
db = stratadb.open(cache=True)      # ephemeral; or open("./app-data") for durable
print(stratadb.agents_guide())      # the entire surface, offline — read this first
  • python -m stratadb.demo — a runnable, zero-setup tour that prints every primitive's real return shape (doubles as a smoke test).
  • stratadb.init("path/to/repo") — scaffold the strata-python agent skill and an AGENTS.md stanza into a repo so the next agent starts warm.
  • npx skills add stratalab/strata-agent-skills — install the full Strata skill set (usage, branching, time travel) for Claude Code, Cursor, Codex, and friends. The same repo (strata-agent-skills) carries the one-command workspace setup (CLI + MCP registration + skills); its npm publish is pending, so use the skills command today.

Names & surfaces

Strata appears under a few names; here is what each string is and where it's used:

Surface Value Notes
PyPI package stratadb pip install stratadb
Python import import stratadb the SDK this README documents
CLI strata a separate binary (strata-core); not installed by this wheel
MCP server strata <db> mcp serve snippet via stratadb.mcp_config(path)
Agent skills npx skills add stratalab/strata-agent-skills one-command setup lives in the same repo (npm publish pending)
GitHub repo stratalab/strata-python this SDK
GitHub org stratalab
Website / docs stratadb.org

Install

uv add stratadb        # or: pip install stratadb

No Rust toolchain required — wheels are prebuilt (abi3, one per platform, Python 3.9+).

Quickstart

import stratadb

db = stratadb.open("./app-data")      # durable (creates if absent)
# db = stratadb.open(cache=True)      # ephemeral, in-memory

# Key-value — values are str | bytes (reads return bytes; misses return None)
db.kv.put("greeting", "hello")
db.kv.get("greeting")                    # b"hello"

# Structured data belongs in the JSON primitive (or json.dumps it into kv)
db.json.set("user:1", {"name": "Ada", "roles": ["admin"]})   # path defaults to "$"
db.json.get("user:1", "$.name")          # "Ada"

# Listing methods return a Page: iterate (auto-paginates) or collect with .all()
db.json.keys(prefix="user:").all()       # ["user:1"]

# Vectors (similarity search with metadata filters)
from stratadb import filters
db.vectors.create_collection("notes", dimension=3)
db.vectors.upsert("notes", "n1", [0.1, 0.2, 0.3], metadata={"kind": "note"})

# Or let the engine embed for you: declare the model, then pass text.
db.vectors.create_collection("docs", dimension=384, embedding_model="miniLM")
db.vectors.upsert("docs", "d1", text="a small domestic cat")
db.vectors.query("docs", text="kitten", k=5)
hits = db.vectors.query("notes", [0.1, 0.2, 0.3], k=5,
                        filter=filters.eq("kind", "note"))

# Events (append-only, hash-chained)
db.events.append("signup", {"user": "ada"})

# Graph
db.graphs.create("social")
db.graphs.add_node("social", "ada")
db.graphs.add_node("social", "grace")
db.graphs.add_edge("social", "ada", "follows", "grace")

db.close()   # or: with stratadb.open("./app-data") as db: ...

stratadb.open() never opens the current directory implicitly: pass a path, set STRATA_DB (stratadb.from_env()), or use cache=True.

Upgrading from pre-V1 (0.x)

V1 namespaced the flat 0.x methods. If an example uses Strata.open or db.kv_put, it predates V1 — the current equivalents:

pre-V1 (0.x) V1 (this SDK)
Strata.open("/path") stratadb.open("/path")
db.kv_put / kv_get / kv_delete / kv_list db.kv.put / .get / .delete / .keys()
db.json_set / json_get / json_delete db.json.set / .get / .delete
db.event_append / event_get / event_list db.events.append / .get / .list
db.vector_create_collection / vector_upsert / vector_search db.vectors.create_collection / .upsert / .query
db.state_set / state_get / state_cas removed — use db.kv or db.json (raises unsupported.sdk.state_removed)
db.transaction() / begin() / commit() removed — writes commit individually; use *_many batches for multi-write commits

Inference — db.ai

Chat, embeddings, and reranking over cloud providers (OpenAI, Anthropic, Google) or local GGUF models — an OpenAI-shaped surface. Strata is embedded and ships no keys: set OPENAI_API_KEY / ANTHROPIC_API_KEY / GOOGLE_API_KEY, or strata config set openai.api_key sk-....

r = db.ai.chat("Explain embeddings in one sentence.",
               model="openai:gpt-4o-mini", max_tokens=60)
print(r.content)

# Structured output (JSON Schema)
r = db.ai.chat("Capital of France and its population?",
               model="anthropic:claude-haiku-4-5-20251001",
               json_schema={"type": "object",
                            "properties": {"capital": {"type": "string"},
                                           "population": {"type": "integer"}},
                            "required": ["capital", "population"]})

# Tool / function calling
r = db.ai.chat("What's the weather in Paris?", model="google:gemini-2.5-flash",
               tools=[{"type": "function",
                       "function": {"name": "get_weather",
                                    "parameters": {"type": "object",
                                                   "properties": {"city": {"type": "string"}},
                                                   "required": ["city"]}}}],
               tool_choice="required")
r.tool_calls          # [{'id': ..., 'function': {'name': 'get_weather', 'arguments': '{"city":"Paris"}'}}]

# Embeddings
e = db.ai.embed(["hello", "world"], model="openai:text-embedding-3-small")
e.vectors             # [[...], [...]]

# A model handle sets load params once
qwen = db.ai.model("local:qwen3", n_ctx=8192)
qwen.chat("Summarize: ...")

db.ai.capability("openai:gpt-4o-mini")   # supported features; no network call

Branches, spaces, and time travel

db.branches.fork("default", "experiment")   # copy-on-write branch
exp = db.at(branch="experiment")          # a scoped view over the same handle
exp.kv.put("k", "only-on-experiment")

db.branches.diff("default", "experiment")      # what differs, per space and primitive (A → B)
db.branches.preview("experiment", "default")   # the conflicts a merge would hit; mutates nothing
db.branches.merge("experiment", "default")     # promote as one atomic commit — strict by default;
                                               # strategy="source_wins" lets the source win conflicts

receipt = db.kv.put("k", "v1")
db.kv.put("k", "v2")
db.kv.get("k", as_of=receipt.commit.timestamp)   # b"v1" — the logical commit timeline
db.kv.get("k", as_of_time=receipt.commit.committed_at)   # b"v1" — real UTC time
stratadb.to_datetime(receipt.commit.committed_at)        # when that commit happened

Two clocks, and they are not interchangeable: timestamp is a position on the logical commit timeline (a counter, never a date) that as_of addresses; committed_at is the UTC instant the commit was applied, which as_of_time addresses and stratadb.to_datetime formats. as_of_time takes a datetime, a date, an ISO 8601 string, or raw epoch microseconds; it refuses rather than clamps outside the branch's dated history (so datetime.now() raises — omit both clocks to read the latest). Passing both raises invalid_argument.executor.as_of_conflict.

merge carries the key-value, JSON, and vector changes a fork made since its fork point; event streams and graphs are compared but never merged. A strict merge that hits a conflict raises errors.ConflictError (conflict.engine.promotion) and writes nothing — preview first.

StrataHub — browse and clone datasets

page = db.hub.list_datasets(tasks="classification", sort="downloads", limit=5)  # default hub: hub.stratahub.io
[d.name for d in page.items]                    # ['titanic', 'iris']; page.total counts every match
card = db.hub.get_dataset("titanic")            # the full card: .readme, .license, .primitives, .clone_command
db.hub.list_refs("titanic").refs                # cloneable branches, each with its manifest hash

titanic = stratadb.clone("titanic", "./titanic",           # a new durable database, cloned from the hub
                         progress=lambda e: print(e.stage.value, e.index, e.object_count))
titanic.json.get("passenger:1")["name"]         # "Braund, Mr. Owen Harris"
titanic.close()

db.hub only reads the hub — it never touches the handle's own data, so any handle (even stratadb.open(cache=True)) can browse. Pass hub_url= or set STRATA_HUB_URL to target another hub; db.hub.info() reports its limits, and db.hub.list_yanked() its takedown list.

Upgrading to 1.2.6 changes the on-disk format. Opening a durable database with this version upgrades it — reading is enough, since the SDK has no read-only open — and an older stratadb or strata CLI then refuses that directory (reporting unavailable.engine.persistence, which looks retryable but is not). Upgrade every reader together, and copy the directory first if you need a way back.

Errors

Every failure raises a typed stratadb.errors.StrataError subclass carrying a stable code, message, hint, and ref. Match on code, never on message:

from stratadb import errors

try:
    db.at(branch="ghost").kv.get("k")
except errors.NotFoundError as e:
    assert e.code == "not_found.engine.branch"
    print(e.ref)   # https://stratadb.org/e/not_found.engine.branch

Misses are not errors — reads return None.

Codes come from two registries: the engine's (strata agents errors) and the SDK's own client-side ones — a closed handle, a bad limit, a datetime handed to as_of. stratadb.errors.catalog() lists the SDK's thirteen with the same fields the engine publishes, and the wheel ships them as sdk-errors.json.

For AI agents

  • stratadb.agents_guide() — the complete offline Python usage guide bundled in the wheel (the SDK-native counterpart to strata agents guide).
  • python -m stratadb.demo / stratadb.demo() — a runnable, zero-setup tour of every primitive with real printed output.
  • stratadb.init(repo_path=".") — scaffold .claude/skills/strata-python/SKILL.md and an AGENTS.md stanza into a repo (idempotent).
  • stratadb.agents_skill() — the strata-python skill markdown, vendored verbatim from strata-agent-skills (tools/vendor_skill.py pins the rev in STRATA_AGENT_SKILLS_REV).
  • stratadb.command_index() — the full command catalog bundled in the wheel.
  • stratadb.mcp_config(path) — the MCP client-config snippet (strata <path> mcp serve; needs the strata binary, a separate strata-core install).
  • db.execute(command: dict) -> dict — the raw command escape hatch (the same wire the CLI and MCP speak); the typed namespaces build on it.

Architecture

Three layers: handwritten ergonomic namespaces over a generated core (one typed method + model per command, generated from the engine's IDL) over a tiny PyO3 binding that links the engine in process. Generated fresh from the IDL (only db.ai's inference family is hand-written), drift-guarded in CI.

Development

python -m venv .venv && source .venv/bin/activate
pip install maturin pytest
maturin develop            # builds the native binding into the venv
python tools/generate.py   # regenerates the typed core from idl/v1/
pytest

Local builds use a path dependency to a sibling ../strata-core checkout; releases pin the git rev in idl/v1/STRATA_CORE_REV (tools/release_prep.py).

License

MIT

Metadata

Release files for stratadb 1.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stratadb 1.2.6
File Size Uploaded Provenance Actions
stratadb-1.2.6.tar.gz 415.0 kB With provenance Details for stratadb-1.2.6.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for stratadb 1.2.6
File Actions
stratadb-1.2.6-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for stratadb-1.2.6-cp39-abi3-win_amd64.whl
stratadb-1.2.6-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for stratadb-1.2.6-cp39-abi3-musllinux_1_2_x86_64.whl
stratadb-1.2.6-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for stratadb-1.2.6-cp39-abi3-musllinux_1_2_aarch64.whl
stratadb-1.2.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for stratadb-1.2.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
stratadb-1.2.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for stratadb-1.2.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
stratadb-1.2.6-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for stratadb-1.2.6-cp39-abi3-macosx_11_0_arm64.whl
stratadb-1.2.6-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for stratadb-1.2.6-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 88.8 MB

Release files / stratadb-1.2.6.tar.gz

Download URL stratadb-1.2.6.tar.gz
Size 415.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7943a01360985cd9172ae5020c09c4d0e38274c92234b439b7e3a78e698f06e3
BLAKE2b-256 checksum
How to use checksums
e9b3e7da8e2bc85e52d5bdcda894f99cc77a65080d745626c4988b239a6a5ace
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-win_amd64.whl

Download URL stratadb-1.2.6-cp39-abi3-win_amd64.whl
Size 10.1 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3b744852cd1ce21f78ee57a30f79684d7cf78f0675b6f2123f8a44f55698bcd4
BLAKE2b-256 checksum
How to use checksums
be33bed1f1c5ef3918e958e21a07904bd8e616500c7d9ccc9bf563363328b6e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL stratadb-1.2.6-cp39-abi3-musllinux_1_2_x86_64.whl
Size 14.1 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
933057681b024ea3dd724ed1817c325d165e60a87a03dc00a9076a61223191f6
BLAKE2b-256 checksum
How to use checksums
dc3224f9c8450b27aaa8ca5b76aba586c66296d9b74f8cab4ecbf2ec618ba8fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL stratadb-1.2.6-cp39-abi3-musllinux_1_2_aarch64.whl
Size 13.6 MB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
5759a8d8d5db7ff5d0b4ce23ca4d70802e03c08c33508b3467bf7e04f4398a55
BLAKE2b-256 checksum
How to use checksums
5ecf2f67151e8bcbf6d45319c7f49c68aa41b28100c460ea8c9b663786b39c76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL stratadb-1.2.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 13.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b94c7b724933c17b3bcbf787021fd387a42bc38cf46ba07a43599801435a0c73
BLAKE2b-256 checksum
How to use checksums
27859109ae82a7b7ce987702d9594cc90faddbd8802fdb32e1ed9f29f6458f25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL stratadb-1.2.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 13.4 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
b1a614e3c5226253d43d3020c8892b07a6e9ad3a7013e5a35b46f05108bcdad4
BLAKE2b-256 checksum
How to use checksums
3b68732fca3fa1a0464ec791bfc1f5e43d8914b8df2d8cbb86e02061dc2cfcf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-macosx_11_0_arm64.whl

Download URL stratadb-1.2.6-cp39-abi3-macosx_11_0_arm64.whl
Size 11.8 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
82e00f047b7c22c99fb017ca4fb616fbc12716ae457af4ec499e682d5a63ddd6
BLAKE2b-256 checksum
How to use checksums
2b5eee771a6567b2b0cb4447e5f01ac76a71d3f7f202dce5859c6f6d951e853e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / stratadb-1.2.6-cp39-abi3-macosx_10_12_x86_64.whl

Download URL stratadb-1.2.6-cp39-abi3-macosx_10_12_x86_64.whl
Size 12.4 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
24ee1cd4b5ba5fd4228223ad5b09723335e458ef25921e9593a63c3e1c81ce8f
BLAKE2b-256 checksum
How to use checksums
16047d0817146fd887addf6f598f6da5efe51e2075f10f1d5e083a251cf8f785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Security for stratadb 1.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for stratadb-1.2.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.6 This release

8 release files Full provenance

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