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.

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 usage guide (identical to strata agents guide).
  • stratadb.command_index() — the full command catalog bundled in the wheel.
  • stratadb.mcp_config(path) — the MCP client-config snippet.
  • 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.0.tar.gz (238.7 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.0-cp39-abi3-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

stratadb-1.0.0-cp39-abi3-musllinux_1_2_x86_64.whl (11.3 MB view details)

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

stratadb-1.0.0-cp39-abi3-musllinux_1_2_aarch64.whl (10.9 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

stratadb-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.5 MB view details)

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

stratadb-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

stratadb-1.0.0-cp39-abi3-macosx_11_0_arm64.whl (9.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

stratadb-1.0.0-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.0.tar.gz.

File metadata

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

File hashes

Hashes for stratadb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 af40a1960cd3ab95b76bfc0c5c8b4edf34b48b8d777592b21f3c2f22fe9fb88d
MD5 2bcfd260ccb5c2b4be99d1a6e80c8aef
BLAKE2b-256 e8306918424d56dbf7914a256c05fcebdf6585756d4964c23679cf1824cf60c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0.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.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: stratadb-1.0.0-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.12

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4b92da14a56aad3ce88e95fc9cb89c834a395fbb37e5156aaddf38589c5ab952
MD5 2d6bf7b058973bac5345cc3dfbf44731
BLAKE2b-256 412b88f8494141c534794cce94367e6ae5e42748d718b8b3d71fc1b190dc2ec2

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd538f8dda3c25de2962ec290b601057b926370cab6767fa624740605ba2a6a0
MD5 e0432d2ab8c3540deaa606a7a3fd7cf9
BLAKE2b-256 c05af9944211c7298ed2eb0cb9d8a293abe25172f46d50b14048766b0c7fe8a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e4b270841a6e62a33e09a5a702d5ba57a9fb50e0957e551137f56498b55f8d9c
MD5 a413eac014f8638c90f78d380667da1a
BLAKE2b-256 c4bfa195316c9e0b4de37480c03fb3f0f366d9976778a9374ad688e5e2dd0185

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5da3dd28fc9580a8c6728a452bffcc0cffa297b5ffbb7a84bc2f7b8595e092d
MD5 2b8235ca1d5dc1c1ee493c28b1357658
BLAKE2b-256 12da5e2b3fbb863cf9a8f65b4e1c27e94c5892303b662ff49a0f428a3a640024

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a1e5e7954a6de293e2297ace50ae4349cec1a27f1f27ba6a049b8ec4bf13ef8d
MD5 229c1ed683739bc8edfcd04bda0220d1
BLAKE2b-256 a300be3657f590b1341ea4420aa11c6d8ab3642b1695eada2ebd35037aa5821b

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54741ce1be2e9f80564a5025e3c592d11867915c109a96e9aa1c8d310cc7a40c
MD5 0547d1ffa9c3fa9c2cc02f18dea46b51
BLAKE2b-256 0210860bbe2ba1fcd9c124f7678c001cd7155e41f768de3fe2fab7c9aa6bbc90

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for stratadb-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ef5d7af78bf97f45d452d6d82f8394f9689facaa114afc58b0941200cd1d19ec
MD5 6a1430fe0a7889e4597c75727bf2e73d
BLAKE2b-256 4e4c01a7585e971735c72765cd9958a9f6c307c681c22270e84cbaf542236db2

See more details on using hashes here.

Provenance

The following attestation bundles were made for stratadb-1.0.0-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