Skip to main content

Strata — an embedded multi-model database for AI agents (Python SDK)

Project description

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.

Six 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 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 agent skill and an AGENTS.md stanza into a repo so the next agent starts warm.

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)
GitHub repo stratalab/strata-python this SDK
GitHub org stratalab
Website / docs stratadb.org

Install

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
db.kv.put("greeting", "hello")
db.kv.get("greeting")                    # b"hello"

# JSON documents
db.json.set("user:1", "$", {"name": "Ada", "roles": ["admin"]})
db.json.get("user:1", "$.name")          # "Ada"

# 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"})
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_edge("social", "ada", "follows", "grace")

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

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

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("main", "experiment")   # copy-on-write branch
exp = db.at(branch="experiment")          # a scoped view over the same handle
exp.kv.put("k", "only-on-experiment")

receipt = db.kv.put("k", "v1")
db.kv.put("k", "v2")
db.kv.get("k", as_of=receipt.commit.timestamp)   # b"v1" — every read takes as_of

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.

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/SKILL.md and an AGENTS.md stanza into a repo (idempotent).
  • stratadb.agents_skill() — the Claude Code skill markdown (version-stamped).
  • 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. Data-plane only — generated fresh from the IDL, 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

Project details


Download files

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

Source Distribution

stratadb-1.0.1.tar.gz (246.5 kB view details)

Uploaded Source

Built Distributions

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

stratadb-1.0.1-cp39-abi3-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

stratadb-1.0.1-cp39-abi3-musllinux_1_2_x86_64.whl (11.4 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

stratadb-1.0.1-cp39-abi3-musllinux_1_2_aarch64.whl (11.0 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

stratadb-1.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.6 MB view details)

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

stratadb-1.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

stratadb-1.0.1-cp39-abi3-macosx_11_0_arm64.whl (9.7 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

stratadb-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file stratadb-1.0.1.tar.gz.

File metadata

  • Download URL: stratadb-1.0.1.tar.gz
  • Upload date:
  • Size: 246.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for stratadb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5a7963210549a35b5ce75db26211853d7b14498ffdcc23466947ebff3c96fb8b
MD5 6745d7e7d38ea5da3df8102a596dc366
BLAKE2b-256 b97c711dd389e945800f7b07a625ab401cb9933362923aeb7204b13dba473b59

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1.tar.gz:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: stratadb-1.0.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bff830b9bada8a2f3823c5d8d893008033317d70c4a708672bb8b3a3a5e6736b
MD5 f95fcd567258aabaf729336861f55c56
BLAKE2b-256 9c4f327e818a111d2ece2fd559edc5ab0fb93a52595ab12ef9ed1b3524751744

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-win_amd64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1da06557a7ea56ba596b03cbebdd820db181a39e4a36ffaaa29d1a5fa503a4f3
MD5 3e19413a7f1a0c647e76230a0cbb0af3
BLAKE2b-256 29026ab21aaa280aa493382c00b3c55ba9879ec96d43e3b6880f9f9c7d80fc6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f8636bae39a41e5612a959442e662cbf31e4799d02090910153cb014c56f4263
MD5 561850d04d396475ba932edca7de2474
BLAKE2b-256 b2917b0b30122a7630a857be1177e5bfa4c89ad80ff3f6e005287daf64a65d90

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19fc314c8dbe5a1393c0e4db61b64c02f92445c3bbc3b62bc2270ba71d10434e
MD5 cb781166077532600e9591b75cd33856
BLAKE2b-256 c6baee8de051b034e01452b927ec25a00a244e66a4c3200496f7ccbd329c02d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2bea87376be9e2c2e27d3afaf1626f8dcd6eeec53f9828ed7483ec51874d650c
MD5 160578bd18441e7098087abe68a6d84a
BLAKE2b-256 6e702f3e624a67e07f07ae0da8eb1648ef7e3b3eda02c4d23b90a2e6949e25d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 886a13c748d47740d5c5b6de3aca34302d66269f1b3b4f2315d2f496d403fdcb
MD5 5645c8ad618cf5a35b38b7502682a3bd
BLAKE2b-256 0699b22aa8d59dd0fe957e8db5cfd5f96bfac1e418ce1e03a3f6695e87f686f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stratadb-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eed5557ab86c75fb9b8bf94cf75c587f8fd2d007366c2cda161c51f0c30ea3b3
MD5 bf6f87ea632fb853ba83f2c0966bd7de
BLAKE2b-256 c2b34b88b4f87213114d20fda46b1516ffca9e10235ab0d10fe440be51f0b001

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on stratalab/strata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page