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.
pip install pytautomaton
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").doing("unlock").when("coin") \
.coming_from("unlocked").go_in("unlocked").when("coin") \
.coming_from("unlocked").go_in("locked").doing("lock").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.
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.