Skip to content

doloopuntil/dlu-afsm

Repository files navigation

A(ttrs) Finite State Machine

A(ttrs) Finite State Machine (afsm) is a simple decorator-based finite state machine library, compatible with attrs and dataclasses.

Example

from dataclasses import dataclass
from enum import auto
from afsm import State, StateMixin, transition
class MachineState(State):
    INITIAL = auto()
    FINAL = auto()
@dataclass  # Or @define if using attrs
class AFiniteStateMachine(StateMixin, initial_state=MachineState.INITIAL):
    @transition(from_=MachineState.INITIAL, to_=MachineState.FINAL)
    def to_final_state(self):
        print("Transitioning to final state")
>>> afsm = AFiniteStateMachine()
>>> afsm.to_final_state()
Transitioning to final state
>>> afsm.to_final_state()
Traceback (most recent call last):
    ...
afsm._state.StateError: Actual state for 'AFiniteStateMachine' does not match expected state(s)
Expected states: INITIAL
Actual state: FINAL

Development

  • Run git clone
  • Run pdm install
  • Run pdm run pre-commit install to install pre-commit hooks.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages