This release is a pre-release and may not be stable for production use.
Fluidstate
Compact statechart that can be vendored.
How to use
A very simple example taken from specs.
>>> from fluidstate import StateChart
>>> class SimpleMachine(StateChart):
... __statechart__ = {
... 'name': 'machine',
... '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.state
'State(created)'
>>> machine.queue()
>>> machine.state
'State(waiting)'
>>> machine.process()
>>> machine.state
'State(processed)'
>>> cancel_machine = SimpleMachine()
>>> cancel_machine.state
'State(created)'
>>> cancel_machine.cancel()
>>> cancel_machine.state
'State(canceled)'
A slightly more complex example
For demonstrating more advanced capabilities::
>>> from fluidstate import StateChart
>>> class Relationship(StateChart):
... __statechart__ = {
... 'initial': 'dating',
... 'states': [
... {
... 'name': 'dating',
... 'transitions': [
... {
... 'event': 'get_intimate',
... 'target': 'intimate',
... 'cond': 'drunk',
... }
... ],
... 'on_entry': 'make_happy',
... 'on_exit': 'make_depressed',
... },
... {
... 'name': 'intimate',
... 'transitions': [
... {
... 'event': 'get_married',
... 'target': 'married',
... 'cond': 'willing_to_give_up_manhood',
... }
... ],
... 'on_entry': 'make_very_happy',
... 'on_exit': 'never_speak_again',
... },
... {
... 'name': 'married',
... 'on_entry': 'give_up_intimacy',
... 'on_exit': 'buy_exotic_car',
... }
... ]
... }
... def strictly_for_fun(self) -> None:
... pass
... def drunk(self) -> bool:
... return True
... def willing_to_give_up_manhood(self) -> bool:
... return True
... def make_happy(self) -> None:
... pass
... def make_depressed(self) -> None:
... pass
... def make_very_happy(self) -> None:
... pass
... def never_speak_again(self) -> None:
... pass
... def give_up_intimacy(self) -> None:
... pass
... def buy_exotic_car(self) -> None:
... pass
# >>> relationship = Relationship()
States
A Fluidstate 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 the 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 Fluidstate 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 fluidstate
Test
tox
Attribution
Fluidstate is forked from https://github.com/nsi-iff/fluidity created by Rodrigo Manhães.
Metadata
Release files for fluidstate 1.1.0a8
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 | |
|---|---|---|---|---|
| fluidstate-1.1.0a8.tar.gz | 12.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fluidstate-1.1.0a8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / fluidstate-1.1.0a8.tar.gz
| Download URL | fluidstate-1.1.0a8.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebc8103c9f2a853ac457a3f20b78ea0677f7a345db4d268bd57571504144eeff
|
|
BLAKE2b-256 checksum How to use checksums |
04279d620873a2bf2fe2daef7ab1ec3c907af831b1636e537e6cc53437e0c872
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.7
|
Release files / fluidstate-1.1.0a8-py3-none-any.whl
| Download URL | fluidstate-1.1.0a8-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6082846e800039877429463ef1752e7fa0a7c68e33389391f6c802f6d6dc505a
|
|
BLAKE2b-256 checksum How to use checksums |
469562fb7592d6e2d44248ff97eb95770ba9fbdd46e719dc627fca2b38d9adc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.7
|
Security for fluidstate 1.1.0a8
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.