Skip to main content

Readable run-time state machine

Project description

https://travis-ci.org/jnmclarty/rrsm.svg?branch=master https://coveralls.io/repos/jnmclarty/rrsm/badge.svg

Enables a finite state machine to be created at run-time AND leverage simple attribute syntax creating self documenting code.

Normally these concepts are mutually exclusive, and in any finished design can hard coded. This module is handy during prototyping.

Usage

>>> from rrsm import StateMachine

>>> #Instantiation works with a list of the form ['state', ...]
... #or a dictionary of the form {'state' : value, ...}
... SM = StateMachine(['cool', 'off', 'on', 'warm'])

>>> #checking state works against strings or integers:
... SM == 'cool'
True

>>> #Change the state
... SM('warm')

>>> #using attributes to check state:
... SM == SM.cool
False
>>> SM == SM.warm
True
>>> SM.current_state
'warm'
>>> SM.current_code
3

For hardcoded finite state machines, the Super State Machine project seems like a more promising solution.

This implementation has no dependencies, nor does it import any of the standard library. It should work on any python version, but it’s tested with 2.6, 2.7, 3.3 and 2.4. Some exceptions probably apply to the exception handling. Pun intended.

Install

The easiest way to install is:

pip install rrsm

Project details


Download files

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

Files for rrsm, version 0.2.0
Filename, size & hash File type Python version Upload date
rrsm-0.2.0.zip (6.7 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page