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

Install

The easiest way to install is:

pip install smuggle

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, some exceptions probably apply to the exception handling. Pun intended.

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

rrsm-0.1.0.zip (6.6 kB view hashes)

Uploaded Source

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