Skip to main content

Versatile and flexible Python State Machine library

Project description

pysm - Python State Machine
---------------------------

Versatile and flexible Python State Machine library.


.. image:: https://travis-ci.org/pgularski/pysm.svg?branch=master
:target: https://travis-ci.org/pgularski/pysm

.. image:: https://coveralls.io/repos/github/pgularski/pysm/badge.svg?branch=master
:target: https://coveralls.io/github/pgularski/pysm?branch=master

.. image:: https://api.codacy.com/project/badge/Grade/6f18f01639c242a0b83280a52245539d
:target: https://www.codacy.com/app/pgularski/pysm?utm_source=github.com&utm_medium=referral&utm_content=pgularski/pysm&utm_campaign=Badge_Grade

.. image:: https://landscape.io/github/pgularski/pysm/master/landscape.svg?style=flat
:target: https://landscape.io/github/pgularski/pysm/master
:alt: Code Health

.. image:: https://readthedocs.org/projects/pysm/badge/?version=latest
:target: http://pysm.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status


Implement simple and complex state machines
------------------------------------------

It can do simple things like this:

.. image:: https://cloud.githubusercontent.com/assets/3026621/15031178/bf5efb2a-124e-11e6-9748-0b5a5be60a30.png

Or somewhat more complex like that:

.. image:: https://cloud.githubusercontent.com/assets/3026621/15031148/ad955f06-124e-11e6-865e-c7e3340f14cb.png


Python State Machine
--------------------

`The State Pattern <https://en.wikipedia.org/wiki/State_pattern>`_
solves many problems, untangles the code and saves one's sanity.
Yet.., it's a bit rigid and doesn't scale. The goal of this library is to give
you a close to the State Pattern simplicity with much more flexibility. And,
if needed, the full state machine functionality, including `FSM
<https://en.wikipedia.org/wiki/Finite-state_machine>`_, `HSM
<https://en.wikipedia.org/wiki/UML_state_machine
#Hierarchically_nested_states>`_, `PDA
<https://en.wikipedia.org/wiki/Pushdown_automaton>`_ and other tasty things.


Goals
-----

* Provide a State Pattern-like behavior with more flexibility (see
`Documentation <http://pysm.readthedocs.io/en/latest/examples.html>`_ for
examples)
* Be explicit and don't add any magic code to objects that use pysm
* Handle directly any kind of event or input (not only strings) - parsing
strings is cool again!
* Keep it simple, even for someone who's not very familiar with the FSM
terminology


Features
--------

* Finite State Machine (FSM)
* Hierarchical State Machine (HSM) with Internal/External/Local transitions
* Pushdown Automaton (PDA)
* Transition callbacks - action, before, after
* State hooks - enter, exit, and other event handlers
* Entry and exit actions are associated with states, not transitions
* Events may be anything as long as they're hashable
* States history and transition to previous states
* Conditional transitions (if/elif/else-like logic)
* Explicit behaviour (no method or attribute is added to the object containing a state machine)
* No need to extend a class with State Machine class (composition over inheritance)
* Fast (even with hundreds of transition rules)
* Not too many pythonisms, so that it's easily portable to other languages (ie. `JavaScript <https://github.com/pgularski/smjs>`_).
* Micropython support


Installation
------------

Install pysm from `PyPI <https://pypi.python.org/pypi/pysm/>`_::

pip install pysm

or clone the `Github pysm repository <https://github.com/pgularski/pysm/>`_::

git clone https://github.com/pgularski/pysm
cd pysm
python setup.py install


Documentation
-------------

Read the docs for API documentation and examples - http://pysm.readthedocs.io/

See Unit Tests to see it working and extensively tested.

Micropython support
-------------------
The library works with pyboards!::

import upip
upip.install('upysm')


Links
-----
* `Documentation <http://pysm.readthedocs.io>`_
* `Installation <http://pysm.readthedocs.io/en/latest/installing.html>`_
* `Github <https://github.com/pgularski/pysm>`_
* `Issues <https://github.com/pgularski/pysm/issues>`_
* `Examples <http://pysm.readthedocs.io/en/latest/examples.html>`_


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysm-0.3.9.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

pysm-0.3.9-py2.py3-none-any.whl (13.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pysm-0.3.9.tar.gz.

File metadata

  • Download URL: pysm-0.3.9.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.15

File hashes

Hashes for pysm-0.3.9.tar.gz
Algorithm Hash digest
SHA256 7ff6dfc3d51f1f37419c537484e01ace12987d73bd537fa30a23fa48055ad9de
MD5 2368ad9aabebb1daa8915114020c8b33
BLAKE2b-256 88709b8ab615c3a57f0f5c144086b88951194d843d0ffd395f356375f250fbeb

See more details on using hashes here.

File details

Details for the file pysm-0.3.9-py2.py3-none-any.whl.

File metadata

  • Download URL: pysm-0.3.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.15

File hashes

Hashes for pysm-0.3.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5b8ee9c67e597844d877fc78543573a3fdd851a777c47e7348d8fdd894c4f79d
MD5 f79e925ba7c1b969bc7e28c9c75018fd
BLAKE2b-256 4d7d5b0a2e11c8f2b1f504343b0db4a4f04267e0e07b5b9bcc35b744757d8b74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page