Skip to main content

SQLite for event-sourced state — Python bindings for salamander-db.

Project description

salamander-db (Python)

Native Python bindings for salamander-dbSQLite for event-sourced state. This is a compiled extension (via PyO3 + maturin), so it embeds the engine in your process exactly like Python's built-in sqlite3 module wraps libsqlite3: you open one handle and reuse it. No server, no subprocess.

The binding is a translation layer over the safe, non-generic Rust Engine. Database ownership and cross-thread sequencing live in the core; Python does not contain storage, replay, branching, or projection algorithms.

import salamander

db = salamander.open("./mem", commit_every_count=8)   # one in-process handle
db.append("session-1", {"kind": "user_msg", "text": "hi"})
db.append("session-1", {"kind": "tool_call", "tool": "grep", "args": {"q": "500"}})
db.commit()

for ev in db.replay("session-1"):
    print(ev["offset"], ev["body"])          # -> plain dicts, nested fields intact

The open handle owns the single-writer lock, any registered views, and the group-commit state — which is why it must be long-lived and in-process, not re-created per call.

Build it

Requires a Rust toolchain and Python ≥ 3.9.

python -m venv .venv && source .venv/bin/activate    # Windows: .venv\Scripts\activate
pip install maturin pytest
maturin develop -m salamander-py/Cargo.toml          # compiles + installs into the venv
python examples/py/quickstart.py
python -m pytest examples/py/test_roundtrip.py -v

On a very new Python that the pinned PyO3 doesn't recognize yet, prefix the build with PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 (the abi3 stable ABI is forward-compatible).

API

Python Engine
salamander.open(path, commit_every_bytes=, commit_every_count=, commit_every_millis=) JsonDb::open_with_policy
db.append(namespace, event: dict) -> int append (payload = JSON)
db.append_batch(namespace, events, ...) -> dict atomic batch append with concurrency, idempotency, and durability
db.append_branch(branch, namespace, event) -> int append to an engine branch
db.commit() -> int commit (fsync)
db.head() -> int head
db.uncommitted_count() -> int group-commit tally
db.replay(namespace, start=0, end=None) -> list[dict] replay (literal)
db.register_view(name, key, indexes={}, where_field=, where_value=) register an IndexedView
db.view(name) -> View typed query handle
db.deregister_view(name) -> bool deregister
db.fork(namespace, at) -> str create branch (returns branch name)
db.history(namespace) -> list[dict] default-branch replay
db.branch_history(branch, namespace) -> list[dict] inherited branch replay

View handles support .get(key), .by(index, key), .range(lo, hi), .prefix(p), .len().

Atomic batches and concurrency

append_batch exposes the engine's complete append contract. Every event is a descriptor with a required body and optional event_type, schema_version, metadata (byte strings or UTF-8 strings), and a 32-digit hexadecimal event_id:

receipt = db.append_batch(
    "orders",
    [
        {
            "body": {"order_id": "o-1", "state": "created"},
            "event_type": "order.created",
            "schema_version": 2,
            "metadata": {"trace_id": "trace-1"},
        },
        {
            "body": {"order_id": "o-1", "state": "paid"},
            "event_type": "order.paid",
        },
    ],
    expected_revision="no_stream",  # or "any" / an exact non-negative revision
    idempotency_key="create-o-1",   # bytes and UTF-8 strings are accepted
    durability="sync",              # "buffered" / "flush" / "sync"
)

The batch is visible all-or-nothing. Identical retries with the same idempotency key return the original receipt; conflicting reuse raises salamander.ConflictError and writes nothing. The other stable exception categories include InvalidArgumentError, NotFoundError, LockedError, IoError, CorruptionError, UnsupportedFormatError, CodecError, ResourceLimitError, and CancelledError. They retain compatibility with their former built-in bases (ValueError, KeyError, OSError, or RuntimeError).

Pass branch="branch-name" to append the batch to an existing branch. Optimistic revisions are branch-local: inherited history is replay-visible, but the first local write to a stream on a new child branch uses expected_revision="no_stream" (or "any"). Replay rows include event and batch IDs, batch index, stream revision, event type, schema version, codec, and metadata in addition to offset, timestamp_ms, and body.

Payloads are any JSON-able Python value (dict/list/str/int/float/ bool/None), converted to/from serde_json::Value at the boundary. Views are declared by field name (primary key, indexes mapping name→field, an optional where_field/where_value filter) — no per-event Python callback crosses the FFI boundary.

A LangGraph checkpointer that survives process restarts ships in examples/py/; an MCP server is on the roadmap. Branch lifecycle and ancestry use the same engine catalog as Rust:

ancestry = db.branch_ancestry(branch_name)  # root-first metadata dictionaries
archived = db.archive_branch(branch_name)  # history remains readable

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

salamander_db-0.1.1.tar.gz (124.6 kB view details)

Uploaded Source

Built Distributions

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

salamander_db-0.1.1-cp39-abi3-win_amd64.whl (708.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

salamander_db-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (880.2 kB view details)

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

salamander_db-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (869.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

salamander_db-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (782.6 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

salamander_db-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (833.5 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file salamander_db-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for salamander_db-0.1.1.tar.gz
Algorithm Hash digest
SHA256 18fdef094c35f44e8d3092b170e4e6e4dbf35e68a292446488f572ca33c2b2db
MD5 3eacf078f0d11964cd26246b55039bfe
BLAKE2b-256 4bd76d3e25b12869d539d36b06674ddb307f8d343b1a52b25c9c3d3af09fc00e

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.1.tar.gz:

Publisher: release-python.yml on rdelprete/salamander-db

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

File details

Details for the file salamander_db-0.1.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: salamander_db-0.1.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 708.0 kB
  • 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 salamander_db-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e34926eb74fc922bcfe947150d414fc28d5ca86c2d79de963212355d8f5e6c42
MD5 0ae781d8971da75aa74ab60ba06d1f62
BLAKE2b-256 2b2655ffae99948bd778121b52088bba02b54a3bf483b29ba5f308d19c5362ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.1-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on rdelprete/salamander-db

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

File details

Details for the file salamander_db-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffc14168d62487a3fea5611d43dc3f19991d9dbd981b6eac83ebc6600c7149a6
MD5 5aa62576bf7230ce1ab160c779c57ff2
BLAKE2b-256 0e65acb1fb9b0210d12fa3c3869442fb9c49bbdbd9068086a058948889307814

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on rdelprete/salamander-db

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

File details

Details for the file salamander_db-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8b7f6dc593e17939daa4ee14679fc78d9ced696c6d3f03c2753518ca8ffa9237
MD5 d787ecb95b703b61b1e0e70b16c5b875
BLAKE2b-256 697d5e0440f9c7adbfa4245fccb5a8e79fc8c9df916564ff34ae9871cd0ee026

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on rdelprete/salamander-db

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

File details

Details for the file salamander_db-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a443014c24282ff15e7416453bd0300a3275b876d4c2098f37799bf8c93a9318
MD5 e7cc9f64ea2908e5a19fbf13e722e067
BLAKE2b-256 5246008180acea5a54cde7cc63873d20a3bcfac0e9a77635dcb8cd75ace34da2

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on rdelprete/salamander-db

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

File details

Details for the file salamander_db-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bc09a62d80ce2f2641ed5606501a8ba6685e8f0a05114eb7c12c1cd5ec4463dd
MD5 501e11df0a4233739cccff89a9c82e59
BLAKE2b-256 de09aa8d2b7d00a6966a5f0548c3bc8080de47c8832ba2c1edf144628abacdf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on rdelprete/salamander-db

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