API Docs

class automat.MethodicalMachine

A MethodicalMachine is an interface to an Automaton that uses methods on a class.

input()

Declare an input.

This is a decorator for methods.

output()

Declare an output.

This is a decorator for methods.

This method will be called when the state machine transitions to this state as specified in the decorated output method.

state(initial=False, terminal=False, serialized=None)

Declare a state, possibly an initial state or a terminal state.

This is a decorator for methods, but it will modify the method so as not to be callable any more.

Parameters:
  • initial (bool) – is this state the initial state? Only one state on this automat.MethodicalMachine may be an initial state; more than one is an error.

  • terminal (bool) – Is this state a terminal state? i.e. a state that the machine can end up in? (This is purely informational at this point.)

  • serialized (Hashable) – a serializable value to be used to represent this state to external systems. This value should be hashable; unicode() is a good type to use.

MethodicalState.upon(input, enter=None, outputs=None, collector=<class 'list'>)

Declare a state transition within the automat.MethodicalMachine associated with this automat.MethodicalState: upon the receipt of the input, enter the state, emitting each output in outputs.

Parameters:
  • input (MethodicalInput) – The input triggering a state transition.

  • enter (MethodicalState) – The resulting state.

  • outputs (Iterable[MethodicalOutput]) – The outputs to be triggered as a result of the declared state transition.

  • collector (Callable) – The function to be used when collecting output return values.

Raises:
  • TypeError – if any of the outputs signatures do not match the inputs signature.

  • ValueError – if the state transition from self via input has already been defined.