SACB / source /corpus /python /ledger /repo /README.md
ilintar's picture
Add corpus source: base repos, task overlays, hidden tests, and the authoring tools
9368cc4 verified
|
Raw History Blame Contribute Delete
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.