|
Download source/corpus/python/ledger/repo/README.md from ilintar/SACB: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/ilintar/SACB/resolve/main/source/corpus/python/ledger/repo/README.md
- Command line
-
hf download hf://datasets/ilintar/SACB/source/corpus/python/ledger/repo/README.md
-
curl -L -o README.md https://huggingface.co/datasets/ilintar/SACB/resolve/main/source/corpus/python/ledger/repo/README.md
1.05 kB
ledger
A small event-sourced inventory ledger.
Everything that happens to stock is recorded as an immutable event in the
EventStore. Current state is never stored directly; it is derived by folding
the event log through a projection.
from ledger import EventStore, StockProjection
store = EventStore()
store.receive("widget", qty=100, unit_cost=2.50)
store.ship("widget", qty=30)
stock = StockProjection()
stock.catch_up(store)
stock.on_hand("widget") # 70
Layout
| module | role |
|---|---|
events.py |
immutable event types |
store.py |
append-only log, owns sequence numbering |
projections.py |
StockProjection (units) and Valuation (FIFO cost) |
policies.py |
reorder suggestions and multi-warehouse allocation |
errors.py |
exception hierarchy |
Resuming a projection
Projections are incremental. Each remembers the last sequence number it applied and asks the store only for events after it, so catching up a long ledger does not mean replaying it from the beginning.