Super State Machine
Super State Machine gives you utilities to build finite state machines.
Free software: BSD license
Documentation: https://super_state_machine.readthedocs.org
Features
Fully tested with Python 2.7, 3.3, 3.4 and PyPy.
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 False >>> task.set_draft() >>> task.state 'draft' >>> task.state = 'scheduled' >>> task.is_scheduled True >>> task.state = 'process' >>> task.state 'processing' >>> task.state = 'wrong' *** ValueError: Unrecognized value ('wrong').Define allowed transitions graph, define additional named transitions and checkers:
>>> class Task(machines.StateMachine): ... ... class States(Enum): ... ... DRAFT = 'draft' ... SCHEDULED = 'scheduled' ... PROCESSING = 'processing' ... SENT = 'sent' ... FAILED = 'failed' ... ... class Meta: ... ... allow_empty = False ... 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() *** 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'Note, that third argument restricts from which states transition will be added to allowed (in case of process, new allowed transition will be added, from ‘scheduled’ to ‘processing’). No argument means all available states, None or empty list won’t add anything beyond defined ones.
Use state machines as properties:
>>> from enum import Enum
>>> from super_state_machine import machines, extras
>>> class Lock(machines.StateMachine):
... class States(Enum):
...
... OPEN = 'open'
... LOCKED = 'locked'
...
... class Meta:
...
... allow_empty = False
... initial_state = 'locked'
... named_transitions = [
... ('open', 'open'),
... ('lock', 'locked'),
... ]
>>> class Safe(object):
...
... lock1 = extras.PropertyMachine(Lock)
... lock2 = extras.PropertyMachine(Lock)
... lock3 = extras.PropertyMachine(Lock)
...
... locks = ['lock1', 'lock2', 'lock3']
...
... def is_locked(self):
... locks = [getattr(self, lock).is_locked for lock in self.locks]
... return any(locks)
...
... def is_open(self):
... locks = [getattr(self, lock).is_open for lock in self.locks]
... return all(locks)
>>> safe = Safe()
>>> safe.lock1
'locked'
>>> safe.is_open
False
>>> safe.lock1.open()
>>> safe.lock1.is_open
True
>>> safe.lock1
'open'
>>> safe.is_open
False
>>> safe.lock2.open()
>>> safe.lock3 = 'open'
>>> safe.is_open
True
Metadata
Release files for super-state-machine 2.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 | |
|---|---|---|---|
| super_state_machine-2.1.0.tar.gz | 20.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| super_state_machine-2.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 28.3 kB
Release files / super_state_machine-2.1.0.tar.gz
| Download URL | super_state_machine-2.1.0.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbea42b7440255e76726221a8b1c7980d8928d427bc3c25714c10e0c6f15cfe6
|
|
BLAKE2b-256 checksum How to use checksums |
376c6c13e32bf1903f1d71bb21dd8d0b62a7977d514a0d2c399bfaec2e8e4299
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Sep 6, 2025.
Transparency logRelease files / super_state_machine-2.1.0-py2.py3-none-any.whl
| Download URL | super_state_machine-2.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c6a4d07202486096004055c77824d979c59248ea23b689addb46a5867e259821
|
|
BLAKE2b-256 checksum How to use checksums |
e3e9e1286da32d514ab1bab27b0f28b00e012f4634aa4521fff7a17bfd9c302a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Sep 6, 2025.
Transparency log