Skip to main content

SQLite-backed KV store (Rust+PyO3) for large media blobs with structured data support

Project description

KohakuVault

SQLite-backed storage with a Rust engine, Python APIs, and batteries included for blobs, typed columns, and cache-aware indexes.

Quick Start

pip install kohakuvault
from pathlib import Path

from kohakuvault import ColumnVault, DataPacker, KVault

db_path = Path("kohaku.db")

# Key-value blobs
kv = KVault(db_path)
kv["cover:001"] = b"\x89PNG..."  # store large blobs without buffering
assert kv.get("cover:001").startswith(b"\x89PNG")

# Columnar data shares the same SQLite file
cols = ColumnVault(kv)
temps = cols.ensure("temperatures", "f64")
temps.extend([23.6, 23.8, 24.1])

profiles = cols.ensure("profiles", "msgpack")
profiles.append({"id": 1, "name": "Rin", "active": True})
assert profiles[0]["name"] == "Rin"

# DataPacker for standalone serialization
packer = DataPacker("bytes:32")
token = packer.pack(b"session")
assert packer.unpack(token, 0).rstrip(b"\x00") == b"session"

Storage Interfaces at a Glance

Interface Data model Access pattern Backing tables / structures Highlights Best for
KVault Key -> opaque bytes Dict-style kvault (blob) WAL-friendly streaming, retry-aware operations Blobs, media, large files
Column Fixed-size elements Mutable sequence col_meta + col_chunks Batch slice read/write, Rust packing fallback Numeric telemetry, dense metrics
VarSizeColumn Prefixed variable bytes Mutable sequence {name}_data + {name}_idx Size-aware updates, adaptive chunk growth Logs, JSON payloads, text
DataPacker Typed serializer Pack/unpack helpers Pure Rust (no extra tables) MessagePack/CBOR, fixed/variable strings & bytes Preprocessing, custom pipelines
CSBTree Ordered map B+Tree style API Arena-backed cache-sensitive tree Contiguous nodes, iterator & range queries Sorted secondary indexes, metadata
SkipList Ordered map Lock-free (CAS) Lock-free skip list Concurrent inserts/reads without GIL contention Shared read/write heaps, hot paths

Capabilities

  • Rust-powered I/O with Python-first ergonomics (PyO3 bridge).
  • Write-back cache for both key-value and columnar workloads (context manager, daemon auto-flush, capacity guards).
  • Automatic dtype parsing with DataPacker fallback for legacy pack/unpack helpers.
  • Fast range access: Column.__getitem__ batches reads; slice assignment funnels to Rust.
  • Variable-size column maintenance: prefix-sum index, chunk rebuilds, and fragment tracking.
  • Concurrency aware retry logic (_with_retries) that turns SQLite busy states into typed exceptions.
  • Optional CSB+Tree and SkipList implementations for ordered access patterns in the same extension module.

Architecture

Python layer (proxy.py / column_proxy.py)
    -> PyO3 bindings
Rust core (lib.rs)
    -> rusqlite + custom allocators
SQLite storage (single .db + WAL)
  • KVault: mutex-protected connection, optional write-back cache, streaming via BLOB API.
  • ColumnVault: element-aligned chunking, cache buckets per column, adaptive variable-size slices.
  • DataPacker: Rust serializers report elem_size / is_varsize to Python, enabling automatic dtype strategy.
  • SkipList / CSBTree: share Python key wrappers to support arbitrary PyObject ordering.

Performance Snapshot (M1 Max, 50K entries)

  • KVault write with 64 MiB cache: ~24k ops/s at 16 KiB payloads (~377 MB/s).
  • KVault read hot cache: ~63k ops/s at 16 KiB payloads (~987 MB/s).
  • Column extend (i64): ~12.5M ops/s with cache (~95 MB/s), >450x faster than uncached append loops.
  • Column slice read (f64, 100 items): ~2.3M slices/s, 200x faster than per-element fetch.
  • MessagePack column writes: >1M pack/unpack ops/s with Rust DataPacker.

See examples/benchmark.py and examples/benchmark_container.py for reproducible scripts.

Tooling & Extras

  • DataPacker: supports primitives, strings (utf8, utf16le, latin1, ascii), bytes:N, msgpack, cbor, and JSON Schema validation. pack_many/unpack_many enable zero-Python loops for batch work.
  • Write-back cache: vault.cache(...) and column.cache(...) manage flush thresholds, auto daemon threads, and locking (lock_cache) to coordinate multi-column writes.
  • Mixed workloads: share a single SQLite file between KVault and ColumnVault (pass a KVault instance into ColumnVault).
  • Ordered indexes: CSBTree (cache-sensitive B+Tree) and SkipList shipped in _kvault; import from kohakuvault when the extension is built.
  • Error mapping: raw RuntimeError from Rust is translated into KohakuVaultError, DatabaseBusy, NotFound, InvalidArgument, or IoError via errors.map_exception.

Development & Testing

python -m venv .venv && source .venv/bin/activate
pip install -e .[dev]

# Format and lint
ruff check --fix .
black src tests examples
cargo fmt

# Run Python + Rust tests
pytest
cargo test

The repository uses maturin for building the extension; see pyproject.toml for configuration.

License

Apache License 2.0. See LICENSE for details.

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

kohakuvault-0.6.0.tar.gz (148.9 kB view details)

Uploaded Source

Built Distributions

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

kohakuvault-0.6.0-cp313-cp313-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.13Windows x86-64

kohakuvault-0.6.0-cp313-cp313-manylinux_2_34_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kohakuvault-0.6.0-cp313-cp313-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kohakuvault-0.6.0-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

kohakuvault-0.6.0-cp312-cp312-manylinux_2_34_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kohakuvault-0.6.0-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kohakuvault-0.6.0-cp311-cp311-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11Windows x86-64

kohakuvault-0.6.0-cp311-cp311-manylinux_2_34_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kohakuvault-0.6.0-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kohakuvault-0.6.0-cp310-cp310-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10Windows x86-64

kohakuvault-0.6.0-cp310-cp310-manylinux_2_34_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kohakuvault-0.6.0-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file kohakuvault-0.6.0.tar.gz.

File metadata

  • Download URL: kohakuvault-0.6.0.tar.gz
  • Upload date:
  • Size: 148.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kohakuvault-0.6.0.tar.gz
Algorithm Hash digest
SHA256 64dcd5e126f5928fc813514fa5d9073234e076d19b8b8197d1192b6bc3f788ba
MD5 2e8a3fe3bc526a66ed646e449c7c0e95
BLAKE2b-256 c233578d824cf0af3df2803d0e3e0a57851330bff62c2fcec5ae1ae64bab29e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0.tar.gz:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5be49a8a9e8e1c0e4b9bb65101fbe90ca0bb88b1ad95aaabcfab1be5b6e40f70
MD5 ac40f291687dfdd0c89c93e59eea570b
BLAKE2b-256 ff0af4c0cc5a2a2247de7dc3669f8bd74e124cabcaa3b0b77152a4af84f511af

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 476362faa1dd5b84eef5f31f0e461e2995b4da328a0c9ddbb8353c2cf4df0f35
MD5 335dc9ae6c2f454c865e5579ab9cb7fa
BLAKE2b-256 5feadf23b4b668143b80720eb5e083be248c6baa534d03c8d348203edb179b44

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6342f12fa562296edbfe686e660c7c8155fc1c14cac373cb7e0f0300c5cc7ca3
MD5 207d0752eeb725bb752b5a6f67c1f283
BLAKE2b-256 6a7a13b88777171a75bc4e010a68a0997f24a334a742fd9d9a80999d02e83917

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4acd05401b77ce10bebead0add5a881fc9a4cdc8110d25be993230b51d3a89f2
MD5 43fb04012f899301b149ad16501761cf
BLAKE2b-256 9e5b75e48f456569e53f8ad2c23bce84e6bc3876f0473486765b5a3fcd75636f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f593f5fdf65f496883779416bb4ee7c9329d03f4423d26d5b64b19346617abb4
MD5 3665532ff0422477c3d83916d69f2db6
BLAKE2b-256 6e233e3f2851f9a8995fbfec4eda5a20c21d50020cb4af6c119143812f15ccc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f21e8591f27c6d475abc90a335097f040651980d8ce98578a2d17f29428ca352
MD5 3c208c08ad63268c483eac225aeb0d4e
BLAKE2b-256 1e74e45ec729f82937ffee8dd5dbb2a2194923dc9ed27063785c6ff01e068aed

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d8d8892845b418aa7b53d1b4aaee64f8eb9f38fd99cb620f075e8daf8c9c0330
MD5 7f68b077276997d371df5b9dfb9c104f
BLAKE2b-256 6681bad7bdeaae9f82b12f811b95382de5c2cddf5e7eae4d656efa6dfbaea4ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d86fb598816db8821d470b051f5ba8b33e57249ff43e2e673bdab3d2612b64ff
MD5 35eede7f22e736d562bd3c7326fa2f48
BLAKE2b-256 ef5015d0b0bc19dcd6f9227c2262bff70b210435563615fcdf4e00f3b323505a

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dfe225c3b31de61b4275dd82ae748ce8d4edee6d90b54af971d9377dcc5b10e4
MD5 af032353513b75ead7a08f0ee8d6d3b4
BLAKE2b-256 088fc0007d957310fad619fac0ad3be31db1860e526f2911941afe79b641afe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bd0d9c9d1d1f09cec7e26d0dac11170e1798332715cf1ff9969ecaeb6873f433
MD5 3c4aae3c7d44b2fb8a9f7c6b701a0184
BLAKE2b-256 fb8e0827506cbd1a69d8b9cce10b905bebd2450e51c03869e1565fc38f556573

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp310-cp310-win_amd64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d6f6db23434c096eb50f9610036b17c438b4cf04f115595fab95403cf42c288e
MD5 435d15b40b30f642a6378db26909f8c0
BLAKE2b-256 3493e4f48f58a664c276ab8fd3125dcfc260e9bdb2b8551e115c629371ab0157

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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

File details

Details for the file kohakuvault-0.6.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.6.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b2f5d55caa51356a61021c4e249131682d6733b2cfd636a9fd3c70b0fff710db
MD5 062ab780320f8b9e4b35af460c61142c
BLAKE2b-256 2212347056fe7f08e23c0a24a604824577ae8ae067250deafe06cfe19bf29248

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.6.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on KohakuBlueleaf/KohakuVault

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