Giter Club home page Giter Club logo

automaton-4's Introduction

Automaton

A minimal Python finite-state machine.

Automaton requires Python version 3.4 or greater.

Build status Coverage report Documentation status License

Automaton is an easy to use, easy to maintain finite-state machine package for Python 3.4 or greater. The goal here is to have something minimal to enforce correctness and to avoid clutter from useless features.

In order to define an automaton, just subclass a provided base:

>>> from automaton import *
>>>
>>> class TrafficLight(Automaton):
>>>
>>>     go = Event("red", "green")
>>>     slowdown = Event("green", "yellow")
>>>     stop = Event("yellow", "red")

You're done: you now have a new automaton definition that can be instantiated and used as a state machine:

>>> crossroads = TrafficLight(initial_state="red")
>>> crossroads.state
"red"

The automaton can be operated via events: signalling the occurrence of an event to the state machine triggers the evolution of the automaton from an initial state to a final state. You can trigger an event calling the class attributes themeselves:

>>> crossroads.go()
>>> crossroads.state
"green"
>>> crossroads.slowdown()
>>> crossroads.state
"yellow"

An alternative way, more convenient if triggering events progammatically, is to call the event() method:

>>> crossroads.event("stop")
>>> crossroads.state
"red"

Automaton enforces correctness in two ways:

  1. checking that the requested event is valid, that is a transition from the current state to the destination state exists in the state machine definition;
  2. checking whether the state graph representing the automaton is connected or not (that is it must have only one connected component).

Documentation

You can find the full documentation at http://automaton.readthedocs.org.

Contributors

Thanks to @simone-campagna for the countless hints.

automaton-4's People

Contributors

nazavode avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.