larzfsm
Finite state machines.
So much of an app is really a state machine - an order goes draft to shipped, a document draft to published. Modelling that as ad-hoc flags gets tangled. larzfsm lets you declare the states and allowed transitions, then fire events - so illegal moves are impossible and the logic is obvious.
larzscript pkg install fsm
What you get
- Declare (event, from, to) transitions
- fire()/can()/allowed()
- Wildcard '*' sources + history
- on_transition callback
Try it
import "fsm" as fsm
let m = fsm.new("draft")
fsm.transition(m, "submit", "draft", "review")
fsm.transition(m, "approve", "review", "published")
fsm.fire(m, "submit")
print(fsm.state(m))
print(fsm.can(m, "approve"))Output
review true
Why it's in the Larz Stack
larzfsm is a real Larzscript package (larzscript pkg install fsm) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.