Skip to main content

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

Project description

KohakuVault

High-performance, SQLite-backed storage with dual interfaces: dict-like for blobs (key-value) and list-like for sequences (columnar). Rust core with Pythonic APIs.

Quick Start

pip install kohakuvault
from kohakuvault import KVault, ColumnVault

# Key-Value: Store binary blobs (images, files, etc.)
kv = KVault("data.db")
kv["image:123"] = image_bytes
kv["video:456"] = video_bytes

# Columnar: Store typed sequences (timeseries, logs, events)
cv = ColumnVault(kv)  # Shares same database
cv.create_column("temperatures", "f64")
cv.create_column("log_messages", "bytes")  # Variable-size strings

temps = cv["temperatures"]
temps.extend([23.5, 24.1, 25.0])  # Like a list

logs = cv["log_messages"]
logs.append(b"Server started")
logs.append(b"Request processed in 5.2ms")

# Access
print(temps[0])      # 23.5
print(list(logs))    # [b'Server started', b'Request processed in 5.2ms']

Features

  • Dual interfaces: Dict for blobs (KVault), List for sequences (ColumnVault)
  • Zero external dependencies: Single SQLite file, no services required
  • Memory efficient: Stream multi-GB files, dynamic chunk growth
  • Type-safe columnar: Fixed-size (i64, f64, bytes:N) and variable-size (bytes)
  • Rust performance: Native speed with Pythonic ergonomics

Installation

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

Platform Support:

  • ✅ Linux (x86_64)
  • ✅ Windows (x86_64)
  • ✅ macOS (Apple Silicon M1/M2/M3/M4 only - ARM64)
  • ❌ macOS Intel (x86_64) - not supported

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
)

Columnar Storage (NEW!)

List-like interface for typed sequences (timeseries, logs, events):

from kohakuvault import ColumnVault

cv = ColumnVault("data.db")

# Fixed-size types: i64, f64, bytes:N
cv.create_column("sensor_temps", "f64")
cv.create_column("timestamps", "i64")
cv.create_column("hashes", "bytes:32")  # 32-byte fixed

temps = cv["sensor_temps"]
temps.append(23.5)
temps.extend([24.1, 25.0, 25.3])
print(temps[0], temps[-1], len(temps))  # 23.5, 25.3, 4

# Variable-size bytes (for strings, JSON, etc.)
cv.create_column("log_messages", "bytes")  # No size = variable!
logs = cv["log_messages"]
logs.append(b"Short message")
logs.append(b"This is a much longer log entry with details...")
print(logs[0])  # Exact bytes, no padding

# Iterate
for temp in temps:
    print(temp)

Why columnar?

  • Append-heavy workloads (O(1) amortized)
  • Typed data (int/float/bytes)
  • Efficient iteration and random access
  • Dynamic chunk growth (128KB → 16MB per chunk)

See docs/COLUMNAR_GUIDE.md and examples/columnar_demo.py for complete guide.

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 wheels and publishes to PyPI when you push a tag:

# 1. Update version in pyproject.toml and Cargo.toml
# 2. Commit changes
git add pyproject.toml Cargo.toml
git commit -m "Bump version to 0.1.0"

# 3. Create and push tag
git tag v0.1.0
git push origin main --tags

# 4. GitHub Actions will:
#    - Build wheels for all platforms
#    - Create GitHub Release with wheels attached
#    - Publish to PyPI (with skip-existing for safety)

What happens:

  • Wheels are built for Linux, Windows, macOS (Apple Silicon)
  • All wheels are uploaded to the GitHub Release (downloadable)
  • Wheels are published to PyPI
  • If some wheels already exist on PyPI, they're skipped (no error)

License

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

Uploaded CPython 3.13Windows x86-64

kohakuvault-0.2.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.2.0-cp313-cp313-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

kohakuvault-0.2.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.2.0-cp312-cp312-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

kohakuvault-0.2.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.2.0-cp311-cp311-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

kohakuvault-0.2.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.2.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.2.0.tar.gz.

File metadata

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

File hashes

Hashes for kohakuvault-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5e6df5fd2a64be771e0cd50193a6df28cdf2b08b7c0716fe0814d7c0beeb1c33
MD5 66a0c4f8cfe187996c60571085b5c407
BLAKE2b-256 de1ec4a3293623e1613bd1eec1790f37a2f311fe732758c18fe3d0a1deb0ef92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 08aa05f692e8f0512424d89a32271decfd26dac9b28e5ea3b41e07be76e3d333
MD5 cadc51804759973b9050fe47097e2e66
BLAKE2b-256 6e32cb355255893deeb74e19c5d6b98649ee980b5cf9dc4d38645ee9a166718c

See more details on using hashes here.

Provenance

The following attestation bundles were made for kohakuvault-0.2.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.2.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 64f53c2539c5e406be11e68389ad78bfa6181ac14e01fb97713080afbc54c70d
MD5 d925d783848f47745965ceb77b6d87d0
BLAKE2b-256 b3114e924b405e18259d6f3f782f29684f5d3acde8e819a497a1e43623277d62

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc45e4282868664da873beb4e1d9f0256142e799024a5bd5d9d32c6fc5552056
MD5 654cc4966e7f08d80503afa32ff9f347
BLAKE2b-256 9984c2c3465f9bf63fbb2ab33e5a48fb23bbf249626711b5a464fcd06264e976

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e00e49fc16ff87404b2167d3e701e00b1351bc6b425f85428f5cbe6bb212b637
MD5 5c9f956e32712bd66ffaa32112e17d4b
BLAKE2b-256 52019f15745d532f84f5f4d515251dc178441d8e7a54796169f6b8cc67a52fe8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 efe83d25b26393eaa2f32c5c3e33290e6bb9a48267868959c14c37ca2048d1f6
MD5 8b322faf15c10cde22ef115ee6954d66
BLAKE2b-256 a148377ea38681c4e53d56817ee9045bd5e676e91e71f572fac28f835e72677d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a2fb6cd56718fff5b38f80818813d97366f8201131bfcaeb89b867b60fb8b9aa
MD5 2d7d17a504224462979f26e07d510e4b
BLAKE2b-256 2f19c2a2b792be3458a6b74ecbc42b8e92f3fd48e7e2947e5f67f5f1e89a35b2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6b1a0d99eb1f724321a4ca0f465b53aef83bbb869e95ccc3e8686308f9169470
MD5 ab6f4baccac5126fd8101ba5fed6fbb6
BLAKE2b-256 8565bb74b2079436498de92035c73d7605a1b63b46b10036f9d19b8d0a8c6c7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5ae8ad16429b086efc8cf9e389fe33717defb2ad20bf50693e65aafd90631928
MD5 91c86933d4c70b605d8683bd51f91ddc
BLAKE2b-256 f57a549731e38b837b69155fcc0a5b246c4abc5077d9c949753c71ac44ff56d4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b5ca6166a372476ef9649b224c282f0c1fc49e3e386501bc706157669328906
MD5 8e3b94a1945633de8f10f1043b61f8a9
BLAKE2b-256 a77bb096b8d47e276b5040125f25e6a1e2f703344f5eebfa52449daefd5d31ac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 546b884306a356eec10192f42634dda971ce81a0d39482239d587b4ae95ca003
MD5 6070b44d3279f482e63edc5a434ef5e8
BLAKE2b-256 f0eca6fc969fb206930987aeb9586c3383bf68ed04d56c4bb65f5711ffe2c422

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 13e647ab2b61b8b658a47207216aed4af0491e96328bb33686f6289d8425a1e6
MD5 61f862d5f59aaa6bb20c7468d7e1a908
BLAKE2b-256 626565cbec08f22083caab1e0277c6388715cacc8ed51ec10ca2c19aa2c267d2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c52f54634cc6eb1ab86da795ee5833a6078927683587948bc02cef6947dafa55
MD5 5cb0256683302db84cc9a2a9240e1dd8
BLAKE2b-256 43304e78111865047b17646c46ade8159b1ac02ccbe4082fddfc1e46c948db5d

See more details on using hashes here.

Provenance

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