PyStator¶
Configuration-driven, stateless finite state machines for Python — YAML/JSON definitions, guards, actions, optional API, worker, and UI
PyStator is a library for defining finite state machines in declarative config (YAML or JSON), computing transitions from current state + event + context, and running guards and actions. The same model powers an optional REST API, worker queue, and UI when you install the corresponding extras.
At a glance¶
| Area | What it is |
|---|---|
| Core | Stateless StateMachine / builder, process(), hierarchical and parallel states |
| EntitySession | Per-entity wrapper: send(), snapshots, generated helpers |
| Persistence | Pluggable state stores (memory, Postgres, Redis, MongoDB, custom) |
| Runtime | Schedulers (asyncio, Redis, Celery), worker + submit_event, deployment guides |
| Discovery | Inferred FSM candidates, shadow-mode comparison, classification APIs |
| Quality | Lint, hooks, metrics, visualization (Mermaid, DOT, SCXML) |
See Concepts, Architecture, and the API Reference.
Key features¶
-
Declarative FSMs
Define states, transitions, guards, and actions in YAML or JSON.
StateMachineBuilderand declarativecheck:/ effects keep configs readable. -
Hierarchical & parallel
Compound states, regions, and parallel execution patterns for real workflows.
-
State stores
In-memory, PostgreSQL, Redis, MongoDB, or bring your own
StateStoreadapter. -
Worker & schedulers
Queue-backed processing with
pystator worker, delayed transitions, and scaling notes. -
REST API & UI
Optional HTTP API and UI on configurable ports; same FSM definitions end to end.
-
Discovery
Infer candidate machines from observations, compare in shadow mode, and classify state from data.
Quick example¶
Load a machine and process an event¶
from pathlib import Path
from pystator import StateMachineBuilder
machine = StateMachineBuilder.from_yaml(Path("order_fsm.yaml")).build()
ctx = machine.create_context(entity_id="ord-1")
result = machine.process(ctx, "submit")
print(result.new_state, result.effects)
Installation¶
Default local ports (see pystator.config.ports): API 8004, UI 3004, pystator docs serve 5004. Details: Installation.
Architecture overview¶
flowchart LR
subgraph Config["Config"]
Y[YAML / JSON FSM]
end
subgraph Core["PyStator core"]
SM[StateMachine]
G[Guards & actions]
end
subgraph Optional["Optional extras"]
API[REST API]
W[Worker]
UI[UI]
ST[(State stores)]
end
Y --> SM
SM --> G
SM --> ST
API --> SM
W --> SM
UI --> API
Next steps¶
-
Get started
Install, first FSM,
process(), EntitySession, and pointers to the API. -
How-to guides
Architecture, persistence, workers, discovery, linting, and observability.
-
Tutorials
Order workflow and API/UI walkthroughs.
-
API reference
Docstring-generated pages for public Python APIs.
-
Contribute
Contributing, publishing, and release workflow.