a simple library to define reusable Finite State Machines with a fluent delcarative style
Project description
PyAutomaton
Description
PyAutomaton is a simple library implementing Mealy state machines, thus meaning that the events produced by the automaton are determined by the tuple (state, event) and not only on the current state, as happens with Moore state machines.
Installation
pip install pytautomaton
Basic Usage
PyAutomaton offers the possibility of declare State Machines by using a fluent descriptive style.
For example, given the state machine in the following figure:
the code implementing this state machine is:
fsm = Automaton().start_from("locked").go_in("locked").when("push") \
.coming_from("locked").go_in("unlocked").when("coin") \
.coming_from("unlocked").go_in("unlocked").when("coin") \
.coming_from("unlocked").go_in("locked").when("push")
And the machine can run by invoking the fsm object as follow:
fsm('push')
each invocation triggers a state transition and returns the corresponding action, if any.
Dump and restore the state machine
It is possible to dump a state machine. A state machine dump is self consistent, thus meaning that it emodies both the state machine configuration as well as the current state of the automaton:
dumped_machine = Automaton.dump(fsm)
machine = Automaton.load(dumped_machine)
The dump is produced in json format.
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 pyautomaton-0.2.2.tar.gz.
File metadata
- Download URL: pyautomaton-0.2.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.8.13 Linux/5.15.0-47-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0e810312dbe930eb9a0234635e543a41aa95e64432a86e31de80a280a3aaf4c
|
|
| MD5 |
8af39401f5a8394853721e59362a303e
|
|
| BLAKE2b-256 |
2342eea7038ce2ad18d2dd5268b02136efc69e4939d1665e4fc08cb9260fa141
|
File details
Details for the file pyautomaton-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pyautomaton-0.2.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.8.13 Linux/5.15.0-47-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
813f577e6d0b182df33d69b8d244fcd793dea018bff1543d8882cae96d1469dc
|
|
| MD5 |
e680b35b3d168d116aa2ec6ff0a62610
|
|
| BLAKE2b-256 |
5971df8233729f5ee74834b08f476a1e3933cf2793934588af0344c398554e19
|