Skip to main content

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

Project description Latest Version Supported Python versions Wheel status License

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

It has been fully tested with Python 2.7 and all versions from 3.4 to 3.9


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

import xworkflows

class MyWorkflow(xworkflows.Workflow):
    # A list of state names
    states = (
        ('foo', "Foo"),
        ('bar', "Bar"),
        ('baz', "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
<StateWrapper: <State: 'foo'>>
>>> o.state.is_foo
>>> o.state.title
>>> o.foobar()
>>> o.state
<StateWrapper: <State: 'bar'>>
>>> o.state.title
>>> o.blah()
>>> o.state
<StateWrapper: <State: 'baz'>>
>>> o.state.title


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.

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

xworkflows-1.1.0.tar.gz (39.4 kB view hashes)

Uploaded source

Built Distribution

xworkflows-1.1.0-py2.py3-none-any.whl (13.5 kB view hashes)

Uploaded py2 py3

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