Cited, real implementations to study (or point an agent at) when designing or reviewing state-machine code.
enum.Enum— states as first-class, finite, typo-proof values; the foundation the table form assumes. docs.python.org/3/library/enum.html- Generators — the interpreter-maintained state machine: the suspension
point is the state. Every
yield-based parser and pipeline stage is this pattern with zero state fields. docs.python.org/3/reference/expressions.html#yield-expressions asyncio.Tasklifecycle — pending → running → done/cancelled, with rules about which motions exist (cancel()on a done task is a no-op that returns False): a transition table in prose. docs.python.org/3/library/asyncio-task.html
- transitions (pytransitions) — the most-used Python FSM library:
declarative tables, guards ("conditions"), callbacks, hierarchical
machines — this module's
StateMachinegrown to production size. github.com/pytransitions/transitions (unverified) - django-fsm / viewflow.fsm — lifecycle guards on Django model fields:
@transition(source, target)decorators putting the table next to the model it rules. github.com/viewflow/django-fsm (unverified)
- TCP's connection diagram (RFC 9293 §3.3.2) — LISTEN, SYN-SENT, ESTABLISHED, TIME-WAIT... the state machine every networked program rides on, specified as exactly a transition table. rfc-editor.org/rfc/rfc9293 (unverified)
The serious ones publish their table (TCP's diagram, pytransitions'
declaration) rather than burying motion rules in methods — the machine you
can read whole is the feature. And each distinguishes state from data:
asyncio keeps a task's result out of its state set the same way a guard
keeps amount_paid out of an order's.