pyfsm-tool
pyfsm-tool is a module to create and manipulate finite states machines (fsm).
Getting started
Import modules
FiniteStateMachine module:
from pyfsm_tool import FiniteStateMachine, StateBehaviour
Exceptions module:
from pyfsm_tool import FSMException
Create new FSM
The new fsm is empty (No state and no transition).
fsm: FiniteStateMachine = FiniteStateMachine()
Initialize the fsm data store
Initialize fsm data store wit 'message' and 'count' available for all states.
fsm.fsm_data_store = {"message": "", "count": 0}
Create new behaviours
Create new behaviours for fsm states.
- First behaviour: add 'Hello' in fsm data store (key = 'message') and next transition is 't1'
class Behaviour1(StateBehaviour):
def action(self) -> None:
self.state_data_store["message"] += "Hello"
def next_transition_id(self) -> str:
return "t1"
- Second behaviour: add ' ' in fsm data store (key = 'message') and next transition is 't2'
class Behaviour2(StateBehaviour):
def action(self) -> None:
self.state_data_store["message"] += " "
def next_transition_id(self) -> str:
return "t2"
- Third behaviour: add 'world' in fsm data store (key = 'message') and next transition is 't3'
class Behaviour3(StateBehaviour):
def action(self) -> None:
self.state_data_store["message"] += "world"
def next_transition_id(self) -> str:
return "t3"
- Fourth behaviour: add '!' in fsm data store (key = 'message') and next transition is 't4' (itself) if the key 'count' in fsm data store is less than 2 (there is incrementation of fsm data store for key 'count'), else next transition is 't5'
class Behaviour4(StateBehaviour):
def action(self) -> None:
self.state_data_store["message"] += "!"
def next_transition_id(self) -> str:
if self.state_data_store.get("count") < 2:
self.state_data_store["count"] += 1
return "t4"
return "t5"
- Fifth behaviour: display fsm data store (key = 'message') and finish fsm.
class Behaviour5(StateBehaviour):
def action(self) -> None:
print(self.state_data_store.get("message"))
Register all states
- Register first state with first behaviour
fsm.register_first_state(Behaviour1(), "b1")
- Register next states with next behaviours
fsm.register_state(Behaviour2(), "b2")
fsm.register_state(Behaviour3(), "b3")
fsm.register_state(Behaviour4(), "b4")
- Register last state with last behaviour
fsm.register_last_state(Behaviour5(), "b5")
If state behaviour not inherits StateBehaviour class or if state already
exists(same id) or if an argument is None, then FSMException is raise.
try:
fsm.register_state(Behaviour2(), "b2")
except FSMException as error:
pass # or do something...
Register all transitions
fsm.register_transition("b1", "b2", "t1")
fsm.register_transition("b2", "b3", "t2")
fsm.register_transition("b3", "b4", "t3")
fsm.register_transition("b4", "b4", "t4")
fsm.register_transition("b4", "b5", "t5")
If transition already exists(same id) or if an argument is None, then FSMException is raise.
try:
fsm.register_transition("b1", "b2", "t1")
except FSMException as error:
pass # or do something...
Run FSM
fsm.run()
Author
If you have any questions or suggestions, please don't hesitate to contact me : belaich.david@outlook.fr.
Metadata
Release files for pyfsm-tool 0.9.3
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 |
|---|---|---|---|---|
| pyfsm_tool-0.9.3.tar.gz | 5.2 kB | Without provenance | Details for pyfsm_tool-0.9.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfsm_tool-0.9.3-py3-none-any.whl | Python 3 | none | any | Details for pyfsm_tool-0.9.3-py3-none-any.whl |
Total release size: 13.2 kB
Release files / pyfsm_tool-0.9.3.tar.gz
| Download URL | pyfsm_tool-0.9.3.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17b654fd9cf4300280fda808e13554e944f57038cd9a432203597b806a696d77
|
|
BLAKE2b-256 checksum How to use checksums |
baf6c9f0e7a7c9587cf99e285300474f79798026248af0c7ec565b49326114c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / pyfsm_tool-0.9.3-py3-none-any.whl
| Download URL | pyfsm_tool-0.9.3-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3977db87a477d217833d6810dbfb3c8f75be309de8c4fdd298a56a8f5c04f44d
|
|
BLAKE2b-256 checksum How to use checksums |
de0484c119b9dc512498ca345740df11e4c97c785183c892d9edf3e014158f23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for pyfsm-tool 0.9.3
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.