Skip to main content

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.

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: turntile-picture

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyautomaton-0.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyautomaton-0.2.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pyautomaton-0.2.1.tar.gz.

File metadata

  • Download URL: pyautomaton-0.2.1.tar.gz
  • Upload date:
  • Size: 3.9 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

Hashes for pyautomaton-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c49ac05e145f85d95e95f6b3eeb7552e2f89684d16271fb6932a8b4a3f1c93a9
MD5 f34b32814751a98d1d288de06b868692
BLAKE2b-256 6d9a52422c51201d7ab68c946d67e5e43af6c4791c34ffae426b6c157a9f2f5c

See more details on using hashes here.

File details

Details for the file pyautomaton-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyautomaton-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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

Hashes for pyautomaton-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30c329191b36ad419d678d07f8474db8cb76048da078d50e51bc3b546a735006
MD5 7c3d03bcaec9cc2bb338a41852d32c8b
BLAKE2b-256 d78449f2f93315c8d786f5ee6d319eae8668b728fb0ad6d93903e6907d0c577b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page