Skip to main content

pysm

https://travis-ci.org/pgularski/pysm.svg?branch=master https://coveralls.io/repos/github/pgularski/pysm/badge.svg?branch=master Code Health Documentation Status

Python State Machine

The 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, HSM, PDA and other tasty things.

Goals

  • Provide a State Pattern-like behavior with more flexibility

  • Be explicit and don’t add any code to objects

  • Handle directly any kind of event (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).

Installation

Install pysm from PyPI:

pip install pysm

or clone the Github pysm repository:

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

Documentation

Read the docs - http://pysm.readthedocs.io/

Release files for pysm 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysm 0.3.2
File Size Uploaded
pysm-0.3.2.tar.gz 18.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysm 0.3.2
File Interpreter ABI Platform
pysm-0.3.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 30.5 kB

Release files / pysm-0.3.2.tar.gz

Download URL pysm-0.3.2.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
345de2981a3e8e9746e1dfd391c443929fcad51bc2b475131ff36787bec3c99b
BLAKE2b-256 checksum
How to use checksums
166fc010c8d9e6b8158e3496b3a35b095098f19d19a6f4af222dd55b3dc1d9c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pysm-0.3.2-py2.py3-none-any.whl

Download URL pysm-0.3.2-py2.py3-none-any.whl
Size 12.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
21bab83ee26e222ed9b91ca6f62641c275b9d9357efce5adfcf5ffd494ac1851
BLAKE2b-256 checksum
How to use checksums
52e5c64a8293b0f5d5a3d716801c7185ab37526d8220755d4e648df1dbe300d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

1 release file

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page