| 1 | # kvstore |
| 2 | |
| 3 | A tiny transactional key-value store persisted as JSON. |
| 4 | |
| 5 | ## API |
| 6 | |
| 7 | ```python |
| 8 | from kvstore import KV |
| 9 | |
| 10 | kv = KV("store.json") |
| 11 | kv.begin() # open a transaction; required before put() |
| 12 | kv.put("key", value) # stage a write; raises RuntimeError outside a transaction |
| 13 | kv.commit() # atomically persist all staged writes as one commit |
| 14 | kv.get("key") # read a committed value (None if absent) |
| 15 | ``` |
| 16 | |
| 17 | Notes: |
| 18 | |
| 19 | - `put()` outside `begin()`/`commit()` raises `RuntimeError`. |
| 20 | - Each `commit()` appends one line to `<path>.commits` — an audit log of how |
| 21 | many commits touched the store. Batch migrations are expected to commit |
| 22 | **once**. |
| 23 | - Values may be any JSON-serializable object. |
| 24 |