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.
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, with 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
Issues, bug reports, and pull requests are welcome, and so is "I ran it on this board and here's what happened", some of the most useful feedback a hardware project can get. Development happens in the ChuMicro repository, whose contributing guide covers setup and the test workflow.
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
Release files for chumicro-kvstore 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chumicro_kvstore-0.3.2.tar.gz | 23.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chumicro_kvstore-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.9 kB
Release files / chumicro_kvstore-0.3.2.tar.gz
| Download URL | chumicro_kvstore-0.3.2.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d7a0552b45e6a1bf4817d6486f772047ac4d15ff4613e1ca02101c4d9269660
|
|
BLAKE2b-256 checksum How to use checksums |
1d03e5a914f1f5098bbf2e3ebcbbcc7adc66c7908fe77d65b0c15942134867bd
|
| 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 Aug 7, 2026.
Transparency logRelease files / chumicro_kvstore-0.3.2-py3-none-any.whl
| Download URL | chumicro_kvstore-0.3.2-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2814af764275af93011e84a1d1ca3deb68aa5e8178aa96471775a0a3d6c9299
|
|
BLAKE2b-256 checksum How to use checksums |
a7c478ae44cbd02f9e7cf70992bdf4d049e4f85c2127af30239fbb74968cf78d
|
| 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 Aug 7, 2026.
Transparency log