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, parent=None) -> str create branch off parent (default: root timeline); forks of forks supported
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.

Demos ship in examples/py/: dungeon.py (a browser roguelike where rewind is a replay, dying is a fork, and a pull-the-plug button proves the save can't corrupt), chat.py (a chat CLI where rewind, fork, and timeline diff are storage primitives — Claude API when available, offline mock otherwise), unkillable_agent.py (an agent hard-killed mid-task that resumes from replay with exactly-once steps), and a LangGraph checkpointer that survives process restarts. 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.2.tar.gz (125.4 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.2-cp39-abi3-win_amd64.whl (708.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

salamander_db-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (880.7 kB view details)

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

salamander_db-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (870.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

salamander_db-0.1.2-cp39-abi3-macosx_11_0_arm64.whl (783.7 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

salamander_db-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl (834.4 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: salamander_db-0.1.2.tar.gz
  • Upload date:
  • Size: 125.4 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.2.tar.gz
Algorithm Hash digest
SHA256 648a1463256940cb482203e4fdf143101f6ada46f81a8b3fdaa224b871db34a1
MD5 a4415b4c8e6658e8984c635939a87477
BLAKE2b-256 2ef7f0965582123207b33efee3878eebb4e437875be3a7890a612aabff795e87

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.2.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.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: salamander_db-0.1.2-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 708.2 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.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a88faab5a4d0893d1404f97d8b7eb61a59437dba6ae65b17c2c32c9c1f19ed39
MD5 50252fa5d22c3d1803c9b2fbfcf9290e
BLAKE2b-256 6de399f3d2d8b982ac80f2b770191d50718676c1f780a1fdaa57f9c4c6955a2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.2-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.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74d2486d795cdeac260dcb1673d058a20357ccb7703bd9293714d7eaee07ce8e
MD5 2317c117bb53d9773aabec5fccf30d4b
BLAKE2b-256 860de676e2ddb4c24caa5a3d8eabd9eeaedb0ba6accb55b4efa3e8a3c98b4595

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.2-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.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a0cd02b46e163a0f5b15338fb9ec3c5ded186424140ecf80f110258a1dd71ed5
MD5 c223d6a49a65ec61c4f6a9a82c656952
BLAKE2b-256 1ec24f1315a1e4d8546db08075f14e9b247b278042bd3cb013dd2663ca8ed065

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.2-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.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc2ba3d0d02e38a477dad1a1caefe4fe6b9350721f8e388bb760e405e075b399
MD5 4d47488b18a2fb526362f4a5edd87375
BLAKE2b-256 b842c9af891dd8a34c18ce8eae0730470c85829efaa43ee686e395badeeb6ab8

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.2-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.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for salamander_db-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7170d973e5ccf9242b93f69b911bf25813a37f62688323e6de59ba8cb4f1d652
MD5 23d76405bd7c47f11dea77aeb1f7d618
BLAKE2b-256 5c741695ffdd844ce237c01f210a9dc2628ca3c9839b4c96bcaf90d2a7dc99ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for salamander_db-0.1.2-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