API Reference¶
chumicro_kvstore¶
chumicro_kvstore
¶
Persisted runtime state for CircuitPython, MicroPython, and CPython.
KVStore
¶
Persisted key-value store with a mapping-style public API.
Construction reads the backend once; a corrupt payload parks the store
empty with is_corrupt set, but a backend that cannot reach its
substrate at all (missing NVM, unreadable filesystem) raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Backend | str
|
|
'auto'
|
bytes_used
property
¶
Encoded size of the current in-memory dict, not the persisted payload.
reload()
¶
Discard in-memory state and reread from backend.
Raises:
| Type | Description |
|---|---|
KVStoreCorrupt
|
Backend payload failed integrity check. |
commit()
¶
Encode the current dict and persist it through the backend.
Raises:
| Type | Description |
|---|---|
KVStoreFull
|
Encoded payload exceeds |
commit_if_changed()
¶
Commit only when the encoded payload changed since the last persist.
Returns:
| Type | Description |
|---|---|
bool
|
|
pop(key, *default)
¶
Remove key and return its value, or default when supplied.
clear()
¶
Remove every key from the in-memory dict (commit not implied).
update(other)
¶
Merge other into the in-memory dict (commit not implied).
KVStoreCorrupt
¶
Bases: KVStoreError
Persisted state failed its integrity check on load.
KVStoreError
¶
Bases: Exception
Base for every kvstore-specific failure.
KVStoreFull
¶
Bases: KVStoreError
A commit would exceed capacity; the in-memory state is left unchanged.