Skip to main content

SQLite-backed KV store (Rust+PyO3) for large media blobs

Project description

KohakuVault

A high-performance, SQLite-backed key-value store for large media files. Rust core with a Pythonic dict-like interface.

Quick Start

from kohakuvault import KVault

# Dict-like interface for binary data
vault = KVault("media.db")
vault["thumbnail:123"] = image_bytes
vault["video:456"] = video_bytes

# Stream large files without loading into memory
with open("large_video.mp4", "rb") as f:
    vault.put_file("video:789", f)

# Write-back cache for bulk operations
vault.enable_cache(cap_bytes=64*1024*1024)
for i in range(1000):
    vault[f"frame:{i}"] = frame_data
vault.flush_cache()  # Batch commit to disk

Why KohakuVault?

  • No external services: Single-file SQLite database, no Redis/memcached needed
  • Memory efficient: Stream multi-GB files without loading into RAM
  • Fast: Rust implementation with optional write-back caching
  • Pythonic: Feels like a dict, works like a database

Installation

pip install kohakuvault  # When published to PyPI
pip install .            # From source

Development

Prerequisites: Python 3.10+, Rust (rustup.rs)

# Setup
git clone https://github.com/yourusername/kohakuvault.git
cd kohakuvault
python -m venv .venv && source .venv/bin/activate  # or .venv\Scripts\activate on Windows
pip install -e .[dev]
maturin develop  # Build Rust extension (once)

# Workflow
# - Edit Python files → changes live immediately
# - Edit Rust files → run `maturin develop` to rebuild

# Tools
pytest                  # Run tests
black src/kohakuvault   # Format Python
cargo fmt               # Format Rust
maturin build --release # Build production wheel

Usage

Basic Operations

vault = KVault("media.db")

# Dict-like interface
vault["key"] = b"value"
data = vault["key"]
del vault["key"]
if "key" in vault: ...

# Safe retrieval
data = vault.get("key", default=b"")

# Iteration
for key in vault:
    print(f"{key}: {len(vault[key])} bytes")

Streaming Large Files

vault = KVault("media.db", chunk_size=1024*1024)  # 1 MiB chunks

# Stream from file → vault
with open("large_video.mp4", "rb") as f:
    vault.put_file("video:789", f)

# Stream from vault → file
with open("output.mp4", "wb") as f:
    vault.get_to_file("video:789", f)

Bulk Operations with Caching

vault = KVault("media.db")
vault.enable_cache(cap_bytes=64*1024*1024, flush_threshold=16*1024*1024)

# Writes batched in memory
for i in range(1000):
    vault[f"item:{i}"] = data

vault.flush_cache()  # Commit all at once
vault.disable_cache()

Configuration

vault = KVault(
    path="media.db",
    chunk_size=2*1024*1024,   # Streaming chunk size
    retries=10,                # Retry attempts for busy DB
    enable_wal=True,           # Write-Ahead Logging
    cache_kb=20000,            # SQLite cache size
)

API Reference

Constructor

KVault(path, chunk_size=1048576, retries=4, backoff_base=0.02,
       table="kvault", enable_wal=True, page_size=4096,
       mmap_size=268435456, cache_kb=20000)

Methods

Storage

  • put(key, value) - Store bytes
  • put_file(key, reader, size=None, chunk_size=None) - Stream from file-like
  • get(key, default=None) - Retrieve bytes
  • get_to_file(key, writer, chunk_size=None) - Stream to file-like
  • delete(key) - Remove key
  • exists(key) - Check existence

Caching

  • enable_cache(cap_bytes, flush_threshold) - Enable write-back cache
  • disable_cache() - Disable and flush cache
  • flush_cache() - Commit cached writes, returns count

Maintenance

  • optimize() - VACUUM database
  • close() - Flush and close

Dict Interface: vault[key], del vault[key], key in vault, len(vault), vault.keys(), vault.values(), vault.items(), etc.

Exceptions: KohakuVaultError, NotFound, DatabaseBusy, InvalidArgument, IoError

Architecture

Python wrapper (src/kohakuvault/proxy.py)
    ↓ PyO3 bindings
Rust core (src/kvault-rust/lib.rs)
    ↓ rusqlite
SQLite database (bundled)

Why hybrid? Rust handles SQLite operations safely and efficiently. Python provides the ergonomic dict-like interface.

Contributing

# Setup
git checkout -b feature-name
# Make changes
black src/kohakuvault && cargo fmt  # Format
pytest                               # Test
git commit && git push
# Open PR

Releasing

GitHub Actions automatically builds and publishes wheels to PyPI on git tags:

# 1. Update version in pyproject.toml and Cargo.toml
# 2. Create and push tag
git tag v0.1.0 && git push origin v0.1.0
# 3. Wheels auto-build for all platforms and publish to PyPI

See .github/RELEASE.md for detailed release instructions and required secrets setup.

License

MIT - see LICENSE

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.1.0.tar.gz (27.5 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.1.0-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

kohakuvault-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kohakuvault-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kohakuvault-0.1.0-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

kohakuvault-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kohakuvault-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kohakuvault-0.1.0-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

kohakuvault-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kohakuvault-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kohakuvault-0.1.0-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

kohakuvault-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kohakuvault-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for kohakuvault-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f0891d6bd9cdfd084d2a9892f92b09b38305a3727a1bc7fcebbd47a0f920a7de
MD5 fdef253f959263862aed304519facd04
BLAKE2b-256 927a7a9c5e1327eb017e946c9960822f47abc842d65cbe7f375e6c9b307330bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8b7e0c44fc4f4a1661985bd29e3e9b25096072e45a5d8b6fbce870205291a7aa
MD5 7b090304ac3c801bae12784aeb041c74
BLAKE2b-256 7882d00fc7413f91fda555b46e7cc332358e5b2689bebf8b4cbc5d51b9b2ad81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5acfd6fd74356151602ccde5f5778fee498969bed54891865a562b196bd3c1df
MD5 5bf55a90f6312a54389ed6dee357a1e6
BLAKE2b-256 464764e968ad3a733fc52064ff76686573f2ebacf5ca107d35e53c561788c4e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 076138097c96749a67602aa7452973b5a130119f0720630f64cd2a7ebc9aa525
MD5 084efa28efa30b6276176cfb37893292
BLAKE2b-256 98f95eb6280088f95e3b0ea017e62c3cf109eb6dc42d81aff894d9b2a3e6aa00

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d4666fa09a279b89ddb97e98873f5a0e7b1c0d12edcc7e81e5a514125f4ad242
MD5 ab5eabacc91590de4c6b0bbdd463d97e
BLAKE2b-256 60fab0a8d808160b941fa19cac18692c7899a7c76ae1f2cf178c005197b40561

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 306a639383f6a404b385fff3ccfd722fb3e2f96c4892af9ad218a0f6e33e28e7
MD5 3a54137b392f7273310b64951a8e4521
BLAKE2b-256 79f8c1bcb656723ada76e55840f93970fe1826225e2717623ef79e35f03e3a32

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53da72ca81ff5b4c5fd96551d1a72241d1b919d7db43762d0caa87067f775264
MD5 c344a8f6c0d3bb98f3368cdcc062e6b4
BLAKE2b-256 0b4e3dffaa27f29c3e6d9cdd661718f1eaeb1395a397568226526ec2984daf0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c6c5c5ef7d37efd1787f275b92f6e32903e64d78cdfc70c70b5e3f214bb10a15
MD5 b80bf0190a69d060d295eddc7c0de60e
BLAKE2b-256 eac4d173b0df7e83927ad7581afb5bd62b3bda79cb61ef34f5f58ab84c5951ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 88824f58c9f5d64e008e1d712670d2d26e3cb65af40df9695bf26e1d312ce70c
MD5 0bc02339ec33a7fada7bafcab4523cda
BLAKE2b-256 12fbe3c0d5940defc9a2008a439532187503752178d03882166545161cde75a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be24126ad7ce814d7ab06b2b012958ae3646ac950ea49f7abd6cd728553df5ab
MD5 36418ea3e292e08dc55aec79199d3982
BLAKE2b-256 33bd96c884b9dc7d5132760cd3c217caf0e7e7be555a556122a1499efd5c0476

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9deaac53f8bd20ebac44544d17bf1c3640551961b0ccd93aa07ef1b4209ab85d
MD5 28477c2771e8d8a53cea9a9320cbc9b6
BLAKE2b-256 239390ac9e3a7e26f1f62b294312dd515152264e4a44427d5b4b9f8b86a15e8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ac98e5e9ed3333334e60b5f8042ee5d3d47c139904fc4c3d34d436336d9cdc0b
MD5 349cfcd690b327dc303a8df1f1ded0fd
BLAKE2b-256 fc249376c6066a3c470ee2f43fc842d10cb9503e83d69c8d0923f3e5c380cb84

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03104d7ee39c650ca4886707619e5a7761d75a1ec09d0fcf3f886c81401c78b4
MD5 de6d57e9d6fbb44f6c5939e4b40c16c4
BLAKE2b-256 edc5fc576bdb9587417574242e37decb7edc86c653231b11bb783453bee5ab32

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.1.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