Tiny mutable key-value store for persisted runtime state — counters, timestamps, tokens — across CircuitPython, MicroPython, and CPython.
Project description
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`)
circup install chumicro-kvstore
# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle/chumicro_kvstore
# CPython
pip install chumicro-kvstore
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
- PyPI: chumicro-kvstore
- Bundle: ChuMicro-Bundle (CircuitPython & MicroPython)
- Experimental bundle: ChuMicro-Bundle-Experimental
- Source: libraries/kvstore
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 chumicro_kvstore_experimental-0.3.0.tar.gz.
File metadata
- Download URL: chumicro_kvstore_experimental-0.3.0.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1311d7429084076f47029bbf71d21c6d209a9cc68d5404d06f0e466c8ed461a1
|
|
| MD5 |
72f23cc12d5c65fdc9c9c26eb2a269b1
|
|
| BLAKE2b-256 |
5bd9d3ec39fc1a6d42b5d642eda099b5aab7123c728867335afc59681b77736a
|
File details
Details for the file chumicro_kvstore_experimental-0.3.0-py3-none-any.whl.
File metadata
- Download URL: chumicro_kvstore_experimental-0.3.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ba7963ddb5ac7b239c930c2b3029d89b106eb30c1db9f67bc9fbef90eb98fed
|
|
| MD5 |
217b2a68945d04764bd54c23137e986f
|
|
| BLAKE2b-256 |
598451fdb51bac1bda2274d7ae3c43f39290dcaf27d1d0f82a911b469d0f75b7
|