skip to navigation
skip to content

xworkflows 0.4.1

A library implementing workflows (or state machines) for Python projects.

Package Documentation

Latest Version: 1.0.4

XWorkflows is a library to add workflows, or state machines, to Python objects.


It allows to easilly define a workflow, attach it to a class, and use its transitions:

class MyWorkflow(xworkflows.Workflow):
    # A list of state names
    states = (
        ('foo', _(u"Foo")),
        ('bar', _(u"Bar")),
        ('baz', _(u"Baz")),
    # A list of transition definitions; items are (name, source states, target).
    transitions = (
        ('foobar', 'foo', 'bar'),
        ('gobaz', ('foo', 'bar'), 'baz'),
        ('bazbar', 'baz', 'bar'),
    initial_state = 'foo'

class MyObject(xworkflows.WorkflowEnabled):
    state = MyWorkflow()

    def foobar(self):
        return 42

    # It is possible to use another method for a given transition.
    def blah(self):
        return 13

>>> o = MyObject()
>>> o.state
>>> o.state.is_foo

>>> o.foobar()
>>> o.state

>>> o.blah()
>>> o.state


Custom functions can be hooked to transactions, in order to run before/after a transition, when entering a state, when leaving a state, …:

class MyObject(xworkflows.WorkflowEnabled):

    state = MyWorkflow()

    def my_hook(self, *args, **kwargs):
        # *args and **kwargs are those passed to MyObject.foobar(...)

    def my_other_hook(self, result, *args, **kwargs):
        # Will be called just after any transition entering 'bar'
        # result is the value returned by that transition
        # *args, **kwargs are the arguments/keyword arguments passed to the
        # transition.
File Type Py Version Uploaded on Size
xworkflows-0.4.1.tar.gz (md5) Source 2012-08-03 31KB
  • Downloads (All Versions):
  • 0 downloads in the last day
  • 0 downloads in the last week
  • 7864 downloads in the last month