Robust statechart for configurable automation rules.
Project description
Superstate
Robust statechart for configurable automation rules.
How to use
A very simple example taken from specs.
>>> from superstate import StateChart
>>> class SimpleMachine(StateChart):
... state = {
... 'initial': 'created',
... 'states': [
... {
... 'name': 'created',
... 'transitions': [
... {'event': 'queue', 'target': 'waiting'},
... {'event': 'cancel', 'target': 'canceled'},
... ],
... },
... {
... 'name': 'waiting',
... 'transitions': [
... {'event': 'process', 'target': 'processed'},
... {'event': 'cancel', 'target': 'canceled'},
... ]
... },
... {'name': 'processed'},
... {'name': 'canceled'},
... ]
... }
>>> machine = SimpleMachine()
>>> machine.current_state
'AtomicState(created)'
>>> machine.trigger('queue')
>>> machine.current_state
'AtomicState(waiting)'
>>> machine.trigger('process')
>>> machine.current_state
'AtomicState(processed)'
>>> cancel_machine = SimpleMachine()
>>> cancel_machine.current_state
'AtomicState(created)'
>>> cancel_machine.trigger('cancel')
>>> cancel_machine.current_state
'AtomicState(canceled)'
States
A Superstate state machine must have one initial state and at least one other additional state.
A state may have pre and post callbacks, for running some code on state on_entry
and on_exit, respectively. These params can be method names (as strings),
callables, or lists of method names or callables.
Transitions
Transitions lead the machine from a state to another. Transitions must have
both event, and target parameters. The event is the method that have to be
called to launch the transition. The target is the state to which the
transition will move the machine. This method is automatically created
by the Superstate engine.
A transition can have optional action and cond parameters. action is a
method (or callable) that will be called when transition is launched. If
parameters are passed to the event method, they are passed to the action
method, if it accepts these parameters. cond is a method (or callable) that
is called to allow or deny the transition, depending on the result of its
execution. Both action and cond can be lists.
The same event can be in multiple transitions, going to different states, having
their respective needs as selectors. For the transitions having the same event,
only one cond should return a true value at a time.
Install
pip install superstate
Test
tox
Attribution
Superstate is forked from https://github.com/nsi-iff/fluidity created by Rodrigo Manhães.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file superstate-1.6.2a3.tar.gz.
File metadata
- Download URL: superstate-1.6.2a3.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b580de39d3e667a9bb9cf92dd14b801a2884bdfc0765eb41abfea2319a051ab
|
|
| MD5 |
38910128952d89bd04714d4575b79654
|
|
| BLAKE2b-256 |
3da68acf8a76af5d31e14df81222662a0e66328ad65acde406b07a39def8d975
|
File details
Details for the file superstate-1.6.2a3-py3-none-any.whl.
File metadata
- Download URL: superstate-1.6.2a3-py3-none-any.whl
- Upload date:
- Size: 29.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51aa612b2e4f92326f1430b842a9d30ae4dc797314054e2b82642bdf25f1e78e
|
|
| MD5 |
2669c947852e7b72a8296422a1b997f9
|
|
| BLAKE2b-256 |
62f59281f79e241bb4a0b7dbda5312c2842b69b1fb9cf0b27731e05097947293
|