Python - PyTransitions

PyTransitions implements an FSM representation in Python. FSMLang, with the -tpy option, will generate code based on the PyTransitions library.

The option --generate-weak-fns also has meaning for the PyTransitions generator; when set to false, the FSMLang file should contain the necessary user functions in the native impl prologue block; otherwise, run-time exceptions will be raised.

-M and -Md are also supported, providing the expected output.

Only flat machines are supported at this time.

Nuances

PyTransitions represents a different way of looking at finite state machines, as compared to FSMLang’s point of view. These are seen primarily in the handling of event data, and the imperative of having a designated action actually execute.

The Event / Action Model

With FSMLang, actions are the primary focus in event handling. Though it is possible to declare instances in which only a transition is taken to handle an event, these exceptions underscore the primacy of the actions. With PyTransitions, on the other hand, the emphasis is where the name indicates: on the transition.

When an event is presented to an FSMLang machine, if an action is specified for that event in the machine’s current state, that action will be carried out. Then, the machine will take any transition which may be specified. The transition may not be concretely specified until runtime (through a guard or transition function), but no actions are taken by that function; it only chooses a new state.

The PyTransitions code generated by FSMLang preserves the FSMLang semantic.

The Event Data Model

Events bringing in data from the “outside” world are processed in FSMLang before any actions are considered. Actions take any data they need from the machine data structure. This model is preserved in the generated PyTransitions machine.