chumicro-kvstore¶
Tiny mutable key-value store for runtime state that survives reboot.
Counters, timestamps, tokens, and retry budgets that your program writes while it runs and still finds after a power cycle, on CircuitPython, MicroPython, and CPython. You get a dict you assign to and commit() when the change matters; the backend is chosen for the runtime you are on (NVM with CRC framing on CircuitPython, NVS on ESP32 MicroPython, LittleFS elsewhere, in-memory on a host).
Quick example¶
from chumicro_kvstore import KVStore
from chumicro_timing import ticks_ms # separate install: chumicro-timing
store = KVStore(backend="auto") # picks the right backend per runtime
store["boot_count"] = store.get("boot_count", 0) + 1
store["last_seen_ms"] = ticks_ms()
store.commit() # one flush per logical change
Documentation¶
- User Guide: backends and
autoselection, commit semantics, sizing and full-store handling, corruption handling, platform notes - API Reference:
KVStoremethods,commit_if_changed, and theKVStoreFull/KVStoreCorruptexceptions - Testing Helpers: using
FakeKVStorein your tests