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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

kohakuvault-0.2.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: kohakuvault-0.2.1.tar.gz
  • Upload date:
  • Size: 60.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.2.1.tar.gz
Algorithm Hash digest
SHA256 185c0f8965ab796a6a23facc56c71ab33168136a9f1686a0c978af1c9c8d1e21
MD5 41f192de3f47bf2265bcc84e79358145
BLAKE2b-256 5046324268823a33ea3328acf510cc0b4efc197c818cb28e8a2432818e288ff3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e5e2d232caa94f6fcf0c8b41616f0608d75e25edd075e1e3e7490b84b462d5ba
MD5 9ccf0ed506aa168cd971a14f5722ed6c
BLAKE2b-256 28fc920752c7474f6ee9a61625a72fcfb84a05286358997a3cb7850b34cf0408

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 55eb76c7d6deb7bc5f35bb11d35f9ceda026083ccf14580bd76a9e412709c884
MD5 431eff505292350ddc11a54cd3a32efe
BLAKE2b-256 c9ed10ff1c661e56760510f343b10adef0f996ae3f487ec6e07046bfbd59ac8e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0fbf12a8f19aa43b293a70870402a3a4e299d402fe50179e8fcd5a7416975d9f
MD5 23d03ccf926099d1fdba7a85f18ef223
BLAKE2b-256 d5e76868ccb0851704a7e0a4bab3e0e4b3331c705dd7f533f204034f5f70ea38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8c685506e0dc68f564d36fee612e94c743014dea8d2414304f10282bbd00d44b
MD5 0607eb0c1fb83cb641b9612603a37e6f
BLAKE2b-256 da74760928bc7915726146287a8c01888340199edbd4ca75564dceec40c50cbc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9acd1bf6fbb380596025d760fe7b8feb32d35ae988adb55247f79dd5bb7dc54b
MD5 ca1839f62d568e479c7414cc3c70dcde
BLAKE2b-256 ae5783738691873e576a9bf3b7b1780c8b4f2df14fd4c60a9e306a78aedb59f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 52e3f84d3ce9ddc390865d57b8fc3c4b1ef41101c884f54f0e5b2519c6d4fb52
MD5 c9137dc9c42d562101ac572f67d5d892
BLAKE2b-256 0b6bedf5bf96b7dec4b2444d839019f33ed13b7dfa7a3e3aa2beaa4ee0c98077

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d834347f434a79e042839bd6332137a36e614890ecd0e0a7d9a303e25d64da1e
MD5 dd31ba0917988632c87650b9191791c9
BLAKE2b-256 76eceec436747b9e01647e4fb80ec31eb70d3689d72f03be3052bd1040f2a9a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3f9ec4362c415f03dffc2b837ba47039b10d25989a339178b682debe7fa2958e
MD5 4995fb2019743ac5038f408627c9cbe1
BLAKE2b-256 a3d6c6c754414498b8f653eceff38d16e2bb01de304cef4cded8d1f9f843e834

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3401b83755babdc3cfdfec1495c91640840d3ce459ea639460a3e994b7a51427
MD5 d446175301d37b3ea6ef5383485812fb
BLAKE2b-256 bbae0678685a87159fc3f42e634fb8b2bbd25ad2afed7f91d6a8ecaa8728570e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5049a9ed62a090615061c0d3adb58e3043159091faea307a77c47271aa838f78
MD5 a0355d84fecf3b999c1ff8d8680673b0
BLAKE2b-256 e5a3b82c4f3423ac5da84ca4747faf153cbe14b360fedbfc221a8c45d0cd5226

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 afc37f950a64d59da07c796e5a5ea3ad7feff2df43b93f4c13c49f5242f377a1
MD5 fda66438c9c9ce7a8da22f521562a193
BLAKE2b-256 518f38d30269411f36774c58d1737437449dce8871ffab36eaa040a9f27109fd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kohakuvault-0.2.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 658449bf72fc3c70292a383a703c2002f593f6ec51ffa251260f02659a086420
MD5 6eb5615a4e92b1630b5fe9d9ef735544
BLAKE2b-256 2fe02d38d656cbfdc5fcafa5bdca675ece493f41e050310e95d652acaebe8d10

See more details on using hashes here.

Provenance

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