Skip to main content

Fluidity: state machine implementation for Python objects

Project description

State machine implementation for Python objects.

How to use

A very simple example taken from specs:

from fluidity import StateMachine, state, transition

class SimpleMachine(StateMachine):

     initial_state = 'created'

     state('created')
     state('waiting')
     state('processed')
     state('canceled')

     transition(from_='created', event='queue', to='waiting')
     transition(from_='waiting', event='process', to='processed')
     transition(from_=['waiting', 'created'], event='cancel', to='canceled')

For demonstrating more advanced capabilities, a “slightly more complex example” from AASM, the Ruby’s most popular state machine implementation, is reproduced below, using Fluidity:

from fluidity import StateMachine, state, transition

class Relationship(StateMachine):
    initial_state = lambda relationship: relationship.strictly_for_fun() and 'intimate' or 'dating'
    state('dating', enter='make_happy', exit='make_depressed')
    state('intimate', enter='make_very_happy', exit='never_speak_again')
    state('married', enter='give_up_intimacy', exit='buy_exotic_car_and_buy_a_combover')

    transition(from_='dating', event='get_intimate', to='intimate', guard='drunk')
    transition(from_=['dating', 'intimate'], event='get_married', to='married', guard='willing_to_give_up_manhood')

    def strictly_for_fun(self): pass
    def drunk(self): pass
    def willing_to_give_up_manhood(self): return True
    def make_happy(self): pass
    def make_depressed(self): pass
    def make_very_happy(self): pass
    def never_speak_again(self): pass
    def give_up_intimacy(self): pass
    def buy_exotic_car_and_buy_a_combover(self): pass

How to install

First version will be released very soon.

How to run tests

Just run:

make test

for install all test dependencies (Should-DSL and Specloud, at the moment) and run the tests. Fluidity itself has no dependencies.

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

fluidity-sm-0.1.0.tar.gz (4.0 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