state-mate
Generate a python-statemachine implementation directly from a constrained Sismic YAML statechart using Jinja2.
Sismic is the authoritative parser and in-memory model. The generator deliberately does not redefine states, transitions, or the state machine in its own domain model.
Input
statechart:
name: Order
root state:
name: lifecycle
initial: orderable
states:
- name: orderable
transitions:
- event: order
target: ordered
- name: ordered
transitions:
- event: process
target: pending
- name: pending
transitions:
- event: ship
target: shipping
- event: cancel
target: canceled
- event: fail
target: failed
- name: shipping
transitions:
- event: succeed
target: succeeded
- event: cancel
target: canceled
- event: fail
target: failed
- name: succeeded
type: final
- name: canceled
type: final
- name: failed
transitions:
- event: retry
target: ordered
load_statechart() calls sismic.io.import_from_yaml(filepath=...). Sismic therefore performs its normal YAML-schema and statechart validation first.
Architecture
Sismic YAML
|
v
sismic.io.import_from_yaml()
|
v
sismic.model.Statechart
|
+--> validate_supported_subset()
|
v
Jinja2 + small rendering helpers
|
v
python-statemachine source
There is no secondary Machine, State, or Transition model. Sismic objects are passed directly to the renderer and template.
The only derived rendering structure is a grouping of Sismic Transition objects by event. This is needed to generate combined python-statemachine event declarations such as:
cancel = (
states.PENDING.to(states.CANCELED)
| states.SHIPPING.to(states.CANCELED)
)
Supported subset
The generator intentionally targets a flat finite-state-machine subset:
- one compound root state;
- basic and final states directly below the root;
- one initial child state;
- external transitions with one event and one target;
- repeated event names across source states.
The following Sismic features are rejected explicitly because the current python-statemachine output cannot preserve their semantics faithfully:
- nested compound states;
- parallel states;
- history states;
- eventless transitions;
- internal transitions;
- guards;
- transition actions;
- priorities;
- state entry/exit actions;
- state and transition contracts.
Source layout
src/state_mate/
├── __init__.py
├── cli.py
├── loader.py
├── render.py
└── templates/
└── machine.py.j2
loader.py is intentionally limited to loading and subset validation. render.py contains only Python naming helpers, event grouping, and Jinja2 setup.
Install and run
uv sync --extra test
Generate a Python state machine:
uv run state-mate examples/order.yaml \
--output build/order_machine.py
Without --output, generated source is written to stdout:
uv run state-mate examples/order.yaml
Run the tests:
uv run pytest
PlantUML
PlantUML output is intentionally outside this project because Sismic already provides it directly:
uv run sismic-plantuml examples/order.yaml
or programmatically with sismic.io.export_to_plantuml().
Documentation
The project documentation is organized according to Diátaxis and built with MkDocs using the built-in Read the Docs theme.
License
Release files for state-mate 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| state_mate-0.1.0.tar.gz | 17.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| state_mate-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.3 kB
Release files / state_mate-0.1.0.tar.gz
| Download URL | state_mate-0.1.0.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32c206778bc75e899f56dc1d4b5d8de54e680006d286357555b5d7927b167364
|
|
BLAKE2b-256 checksum How to use checksums |
c93529552eca70faea17b6042e0efed74de0a37467fd1b33cd3571216115d3c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / state_mate-0.1.0-py3-none-any.whl
| Download URL | state_mate-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4d0585942e514a787e7c35ad5e97cc4318bad14bea19b65371093c30a75dd7c
|
|
BLAKE2b-256 checksum How to use checksums |
d67534739c4578ac563886f54213bc2b65574c3032cf20148f2187806f3a079c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency log