Super State Machine
Super State Machine gives you utilities to build finite state machines on top
of enum.Enum.
- Free software: BSD license
- Documentation: https://super-state-machine.readthedocs.io
- Source: https://github.com/beregond/super_state_machine
Installation
pip install super-state-machine
Supports Python 3.11 to 3.15, no runtime dependencies.
Features
-
Create finite state machines:
>>> from enum import Enum >>> from super_state_machine import machines >>> class Task(machines.StateMachine): ... ... state = "draft" ... ... class States(Enum): ... DRAFT = "draft" ... SCHEDULED = "scheduled" ... PROCESSING = "processing" ... SENT = "sent" ... FAILED = "failed" >>> task = Task() >>> task.is_draft True >>> task.set_scheduled() >>> task.state 'scheduled' >>> task.state = "processing" >>> task.is_processing True >>> task.state = "wrong" Traceback (most recent call last): ... ValueError: Value wrong doesn't match any state.
-
Define the allowed transitions graph, named transitions and checkers:
>>> class Task(machines.StateMachine): ... ... class States(Enum): ... DRAFT = "draft" ... SCHEDULED = "scheduled" ... PROCESSING = "processing" ... SENT = "sent" ... FAILED = "failed" ... ... class Meta: ... initial_state = "draft" ... transitions = { ... "draft": ["scheduled", "failed"], ... "scheduled": ["failed"], ... "processing": ["sent", "failed"], ... } ... named_transitions = [ ... ("process", "processing", ["scheduled"]), ... ("fail", "failed"), ... ] ... named_checkers = [ ... ("can_be_processed", "processing"), ... ] >>> task = Task() >>> task.state 'draft' >>> task.process() Traceback (most recent call last): ... super_state_machine.errors.TransitionError: Cannot transit from 'draft' to 'processing'. >>> task.set_scheduled() >>> task.can_be_processed True >>> task.process() >>> task.state 'processing' >>> task.fail() >>> task.state 'failed'
transitionsmaps each source state to the states it may move to. The third item of a named transition adds edges from the listed states (herescheduled -> processing). Without it the transition is allowed from every state, andNoneadds the method without touching the graph. -
Use state machines as properties:
>>> from super_state_machine import extras >>> class Lock(machines.StateMachine): ... ... class States(Enum): ... OPEN = "open" ... LOCKED = "locked" ... ... class Meta: ... initial_state = "locked" ... named_transitions = [ ... ("open", "open"), ... ("lock", "locked"), ... ] >>> class Safe: ... ... lock1 = extras.PropertyMachine(Lock) ... lock2 = extras.PropertyMachine(Lock) ... ... @property ... def is_open(self): ... return self.lock1.is_open and self.lock2.is_open >>> safe = Safe() >>> safe.lock1 'locked' >>> safe.lock1.open() >>> safe.lock1 'open' >>> safe.is_open False >>> safe.lock2 = "open" >>> safe.is_open True
Logging
State changes are logged with the standard library logging module at
DEBUG level, using loggers under the super_state_machine name. Logging is
off by default (the package installs a NullHandler). To enable it:
import logging
logging.basicConfig(level=logging.DEBUG)
# or enable it for this library only:
logger = logging.getLogger("super_state_machine")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
Each record contains the class name, instance id and the old and new state,
for example Task (id=140...): draft -> scheduled.
Metadata
Release files for super-state-machine 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| super_state_machine-2.1.1.tar.gz | 24.7 kB | With provenance | Details for super_state_machine-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| super_state_machine-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for super_state_machine-2.1.1-py3-none-any.whl |
Total release size: 33.4 kB
Release files / super_state_machine-2.1.1.tar.gz
| Download URL | super_state_machine-2.1.1.tar.gz |
|---|---|
| Size | 24.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bdee52754b5448a3e9397816579cfed17e0a51a8dc073c5571a54f2a14c8794
|
|
BLAKE2b-256 checksum How to use checksums |
66aaa721e5b5385d1f345f5c1e2505b9e0543182ade20f64053347ddabf993ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 28, 2026.
Transparency logRelease files / super_state_machine-2.1.1-py3-none-any.whl
| Download URL | super_state_machine-2.1.1-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e9476bdfeed8f7bae737c6ef7314e18f617b1a15a1a0ec89c8664a7ecb70b16
|
|
BLAKE2b-256 checksum How to use checksums |
287b52d23a0d3393f6e5240f7d7bb227f0d8f3ca17b8a2f03270fc23ac3f7e2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 28, 2026.
Transparency logSecurity for super-state-machine 2.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for super_state_machine-2.1.1.tar.gz
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 Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.