Fast SQLite-backed mutable mapping for bytes keys and values.
Project description
sqlite-bytes-store
sqlite-bytes-store is a small, typed, dependency-free MutableMapping for
bytes keys and bytes values, backed by SQLite.
It is meant for write-heavy byte stores where a plain dict is too temporary,
shelve is the wrong shape, and the stdlib dbm.sqlite3 backend spends too
much time committing individual updates.
Install
python -m pip install sqlite-bytes-store
uv add sqlite-bytes-store
Usage
from sqlite_bytes_store import SQLiteBytesStore
with SQLiteBytesStore("cache.sqlite") as store:
store[b"alpha"] = b"payload"
store[b"beta"] = b"another payload"
assert store[b"alpha"] == b"payload"
assert store.get(b"missing", b"default") == b"default"
assert b"beta" in store
store.commit()
The store implements collections.abc.MutableMapping[bytes, bytes], so the
usual mapping operations work: len(store), iteration over keys, get,
assignment, deletion, clear, and membership checks.
Useful options:
SQLiteBytesStore(
"positions.sqlite",
reset=False, # remove an existing database before opening
table_name="items", # validated SQLite identifier
commit_interval=10_000, # writes between automatic commits
)
close() commits pending writes and closes the connection. sync() is an alias
for commit() for compatibility with other mapping-store APIs.
Why It Is Fast
The table is deliberately simple:
key BLOB PRIMARY KEYvalue BLOB NOT NULLWITHOUT ROWID- WAL journal mode
synchronous=NORMAL- batched commits
That makes it a focused persistence layer for byte-to-byte data, not a general SQLite abstraction.
Benchmark
The repository includes a reproducible benchmark:
uv run --python 3.14 python benchmarks/benchmark_stores.py --items 2000 --repeats 3
dbm.sqlite3 was added in Python 3.13; the package itself only requires Python
3.10 or newer.
Results from this machine:
- Date: 2026-06-02
- Python: CPython 3.14.2
- SQLite: 3.50.4
- Platform: Linux 5.15.161btrfs, Intel Core i5-7200U CPU @ 2.50GHz
- Workload: 2,000 pre-generated 16-byte keys, 128-byte values, 3 fresh databases
- Metric: median time; speedup is relative to
dbm.sqlite3total time
| Implementation | Insert median | Read median | Total median | Speedup | Disk |
|---|---|---|---|---|---|
| SQLiteBytesStore | 0.0306s | 0.0205s | 0.0537s | 92.73x | 352.0 KiB |
| dbm.sqlite3 | 4.9745s | 0.0103s | 4.9844s | 1.00x | 372.0 KiB |
The read-only path is in the same ballpark here; the big win is the write-heavy
path where SQLiteBytesStore batches commits.
Development
uv sync --group dev --extra docs
uv run ruff format .
uv run ruff check .
uv run python -m pytest
uv build --clear
uv run twine check dist/*
License
sqlite-bytes-store is distributed under the GPL-3.0-or-later license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlite_bytes_store-0.1.0.tar.gz.
File metadata
- Download URL: sqlite_bytes_store-0.1.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9342b1724356e6f01e60a92454e3899aa869dbe848e146dec03d1b514cd8daea
|
|
| MD5 |
5d0aa1768cc3c4043ca27a1f7d970b73
|
|
| BLAKE2b-256 |
997ec50c4b3db12b71fba2cd323e66413bb268ed6c85d1199fcbf4dd914ed74f
|
File details
Details for the file sqlite_bytes_store-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlite_bytes_store-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d974f0064f91e1b258e3e683fbde747c0a2a92f15ad6af05cac71f02a48244e
|
|
| MD5 |
04be8862977ca20b85ce2743248a0beb
|
|
| BLAKE2b-256 |
01fd84fabaa33c47d3d75415b97d4e6b7910775d6194f5032ce15b7138d316da
|