Skip to main content

shelfdb

Tiny LMDB-backed shelf database utilities.

Installation

pip install shelfdb

Development

Python 3.12–3.14 is supported. Development uses Python 3.14, selected by .python-version; compatibility checks cover Python 3.12 and 3.14. Python 3.15 is temporarily excluded because the released dill cannot serialize query callbacks on it; support will be reassessed after an upstream fix is released.

Install development dependencies:

uv sync --dev

Development tooling lives in src/dev/, outside the published shelfdb package. Use --directory src to run its module; workflow commands resolve paths from the repository root. Documentation macros live in src/macros.py.

Unit tests mirror src/ under tests/unit/: shelfdb/, dev/, and macros_test.py. Integration tests cover cross-layer behavior; tests/usage/ contains executable usage examples.

Run the complete non-publishing release gate:

uv run --directory src python -m dev release-check

The gate audits locked dependencies, checks formatting, linting, types, supported Python versions, strict documentation, release artifacts, metadata, and a clean wheel installation. GitHub Actions runs the same gate on pull requests, main, and version tags. Before tagging, authenticated release maintainers also check GitHub's repository alerts:

uv run --directory src python -m dev release-check --github

Serve the docs locally (Zensical dev server; live reload is built in):

uv run --directory src python -m dev docs serve --port 9001 --livereload

--livereload is a legacy compatibility flag and is intentionally ignored by Zensical (as Zensical has built-in live reload for docs serving).

Build docs for verification (Zensical build):

uv run --directory src python -m dev docs build

Publish the docs with mike to the docs branch:

uv run --directory src python -m dev docs publish

Override the publish target when needed:

uv run --directory src python -m dev docs publish --publish-version 3.0.1 --alias latest --branch docs --remote origin

Server

Run the protocol server:

shelfdb server

Run the protocol server on a custom address:

shelfdb server --url "tcp://0.0.0.0:17001" --db-path ./db

Client

Connect a client:

from shelfdb.client import Client

client = await Client.connect("tcp://127.0.0.1:31337")

Unix sockets also work:

from shelfdb.client import Client

client = await Client.connect("unix:///tmp/shelfdb.sock")

Transaction behavior

  • Readers use independent LMDB snapshots and do not join the writer queue.
  • Remote write transactions queue, one writer at a time, across connections served by the same DB object on one event loop. Independent local writers and other server processes are outside this queue.
  • A normal exit from async with client.transaction(write=True) commits; an exception escaping the context rolls back the whole transaction. Catching a query error inside the context leaves commit/rollback up to you.
  • Keep transactions short: perform external HTTP/LLM calls before opening them. Long-lived readers can delay page reuse; long-lived writers hold up the queue.

See remote transaction usage for coordination limits and details on partial updates and error handling.

Large results

Remote messages are buffered, not streamed. The former 1 MiB cap is removed; only the unsigned 32-bit payload length remains (4 GiB minus 1 byte). Large queries can still exhaust memory, so paginate bulk reads with .slice(...). Store large assets externally and keep references in ShelfDB.

See pagination and its limits.

Example

from shelfdb.client import Client

client = await Client.connect("tcp://127.0.0.1:31337")

try:
    async with client.transaction() as tx:
        users = tx.shelf("users")

        count = await users.count().query()
        alice = await users.key("alice").item().query()
        admins = await users.filter(
            lambda item: item.value["role"] == "admin"
        ).sort(reverse=True).query()

    async with client.transaction(write=True) as tx:
        users = tx.shelf("users")

        await users.put("eve", {"role": "user"}).query()
        await users.key("eve").update(
            lambda item: {**item.value, "role": "admin"}
        ).query()
finally:
    await client.close()

Metadata

Release files for shelfdb 3.1.0

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

Source distribution (sdist)

Source distribution for shelfdb 3.1.0
File Size Uploaded
shelfdb-3.1.0.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shelfdb 3.1.0
File Interpreter ABI Platform
shelfdb-3.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.5 kB

Release files / shelfdb-3.1.0.tar.gz

Download URL shelfdb-3.1.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8b348690757b807644b527b3f468d7def4ea4fe909c0659c392676bf83b7abcd
BLAKE2b-256 checksum
How to use checksums
cd93587264651092fa52f42a2adc01f91c9c68f5b276d62bd489dc41a6476db0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / shelfdb-3.1.0-py3-none-any.whl

Download URL shelfdb-3.1.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3e6527e20dcf7e8c926434b52f14146862d7235a0d34c27e7172ed1e31ebd3a
BLAKE2b-256 checksum
How to use checksums
73f6d18ae41f7b28f5de270586edae1780a7e3b416e9694e58a6d11b875a801e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
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