Skip to main content

chumicro-kvstore

A persistent dict for counters, timestamps, and tokens that need to survive a reboot.

A dict-shaped store with commit() semantics. Auto-detects the right backend per runtime (NVM on CircuitPython, NVS on ESP32 MicroPython, LittleFS elsewhere, in-memory for tests), bounds writes with commit_if_changed() so unchanged state doesn't wear the flash, and surfaces capacity and corruption honestly. Not a config system — for declarative settings see chumicro-config.


Part of the ChuMicro family — small, focused Python libraries for microcontrollers and laptops. Browse all libraries.

Install

# CircuitPython (after `circup bundle-add ChuMicro/ChuMicro-Bundle-Experimental`)
circup install chumicro_kvstore

# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle-Experimental/chumicro_kvstore

# CPython
pip install chumicro-kvstore-experimental

For bundle setup, pre-compiled .mpy bundles, the experimental channel, and details on PyPI naming, see the chumicro INSTALL guide.

Quick example

Boot counter that survives reboot:

from chumicro_kvstore import KVStore

store = KVStore(backend="auto")
store["boot_count"] = store.get("boot_count", 0) + 1
store.commit_if_changed()              # no flash write if value unchanged
print(store["boot_count"])             # → 1, 2, 3, … across power cycles

What's included

Symbol What it does
KVStore(backend="auto") Mapping-shaped store; auto-detect picks NVM (CP), NVS (MP-ESP32), LittleFS (MP non-NVS), or memory (CPython)
store[key] / store[key] = v / del store[key] Standard dict semantics
store.commit() Encode + persist current state
store.commit_if_changed() Skip write when payload is unchanged (wear defense)
store.reload() Discard in-memory state, reread from backend
store.capacity / bytes_used / is_corrupt / backend_name Honest substrate introspection
KVStoreFull / KVStoreCorrupt Targeted exceptions (catch KVStoreError for both)
chumicro_kvstore.testing.FakeKVStore Drop-in for downstream tests with capacity + corruption hooks

Where this fits

Leaf — no upstream ChuMicro deps. Used directly in app code; no other ChuMicro library depends on it.

Platform support

Works on CPython, MicroPython, and CircuitPython.

Examples

Example What it shows
boot_counter.py Boot counter persisted across reboots; auto-detect picks the right backend per runtime

Contributing

Working on chumicro-kvstore itself? Clone the mono-repo if you haven't already — the rest of the workflow assumes you're inside that workspace.

pip install -e .[test]
pytest tests/                  # host-side tests
pytest functional_tests/       # on-device tests (needs a board registered in devices.yml)

Register a board before running functional tests: chumicro-workspace add-device <id> --address <port>.

Docs

📖 Stable docs · Experimental docs

Find this library

License

MIT

Release files for chumicro-kvstore-experimental 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chumicro-kvstore-experimental 0.3.1
File Size Uploaded
chumicro_kvstore_experimental-0.3.1.tar.gz 23.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chumicro-kvstore-experimental 0.3.1
File Interpreter ABI Platform
chumicro_kvstore_experimental-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / chumicro_kvstore_experimental-0.3.1.tar.gz

Download URL chumicro_kvstore_experimental-0.3.1.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
af2b2ece79e0f450f22b805f39a7ef93340274078dd46e2b8eba4d2a7fd68140
BLAKE2b-256 checksum
How to use checksums
1fe9a40f26260233a2d485cbc2be662dc9500d828e8888c5e89dfe5d97618c47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 19, 2026.

Transparency log

Release files / chumicro_kvstore_experimental-0.3.1-py3-none-any.whl

Download URL chumicro_kvstore_experimental-0.3.1-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df14c2940249090828638afdfda86a122daeebccb4db1e10a6d07a76d78211d2
BLAKE2b-256 checksum
How to use checksums
98a2d931bbfa35d71a99095ffd445ee192c2be1a2a32b19b584c20327430d3fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 19, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

This release

0.3.1 This release

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page