Automat provides a declarative, self-service API for defining finite-state machines directly within your Python classes. It helps manage complex state transitions and actions in a structured, testable way. The current version is 25.4.16, and it maintains a relatively stable release cadence with minor updates and bug fixes.
pip install automatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a simple state machine for a door with 'closed' and 'open' states, and 'open_door'/'close_door' inputs. It also shows how to associate outputs (actions) with state transitions and how to initialize and interact with the machine.
Always ensure your class's `__init__` explicitly calls `self._machine.initial(self, self.your_initial_state)` to set the starting state.
Always explicitly specify the `enter` argument in `state.upon` if you intend for the machine to transition to a new state. If you mean to stay in the current state, `enter=self.current_state` (or omitting `enter`) is correct.
Design your output methods to accept `self` and use it to interact with the object's internal state or perform side effects directly related to the object.
Always drive state changes through the defined `@_machine.input()` methods. If you need to expose internal state, do so via read-only properties or specific queries, not direct manipulation.
Install the package using pip: 'pip install automat'.
Ensure you are using the correct import statement: 'from automat import MethodicalMachine'.
Verify the installed version of 'automat' and update if necessary: 'pip install --upgrade automat'.
You must define a valid transition for the given input from the current state using `@current_state.upon(input_method, enter=next_state_method, outputs=[output_method1, ...])` or ensure the input is called only when a transition is expected.
Explicitly define how output values are collected using the `collector` argument in `@state.upon()`, or ensure your code correctly handles a list of return values, including potential `None`s, from the input call. Example for `collector`: `@state.upon(some_input, enter=next_state, outputs=[some_output], collector=lambda results: results[0] if results else None)`.
No dependency data recorded yet.