Python state machine libraries

Updated Nov 2026

Python state machine libraries model an object's behavior as a fixed set of states and the transitions between them. A machine accepts only the transitions its definition allows and runs callbacks when the state changes. These libraries keep order workflows, Django models, and AI agent loops in a known state at every step.

Popularity

Automat has the most monthly downloads in this comparison, at 14.8M.

LibraryMonthly downloadsStarsLast releaseLicense
Automat
14.8M
651Apr 2025MIT
Python StateMachine
3.2M
1.3KOct 2026MIT
transitions
2.0M
6.6KJul 2025MIT
Django FSM-2
668.6K
287Oct 2026MIT
Django FSM
553.8K
2.3KNov 2026AGPL-3.0-or-later WITH viewflow-library-exception
fysom
91.8K
398Sep 2021MIT
Automaton
90.2K
62Aug 2026Apache-2.0
Sismic
6.6K
172Oct 2026LGPL-3.0
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryDjango model integrationHierarchical statesAwaits coroutine callbacks
AutomatUnsupportedUndocumentedUnsupported
Python StateMachineBuilt-inBuilt-inBuilt-in
transitionsVia pluginBuilt-inBuilt-in
Django FSM-2Built-inUndocumentedUnsupported
Django FSMBuilt-inUndocumentedUnsupported
fysomUnsupportedUndocumentedUndocumented
AutomatonUnsupportedBuilt-inUnsupported
SismicUnsupportedBuilt-inUndocumented
Built-inVia pluginNot supportedNot documented

Libraries and code examples

Builds finite-state machines.

Downloads / mo
14.8M
Stars
651
Last release
25.4.16
License
MIT

Quickstart

From tutorial.rst
$ pip install automat
from typing import Protocol
from automat import TypeMachineBuilder

class Inputs(Protocol):
    def finish(self) -> None: ...

builder = TypeMachineBuilder(Inputs, object)
start = builder.state('start')
done = builder.state('done')
@start.upon(Inputs.finish).to(done)
def finish(controller: Inputs, data: object) -> None:
    pass
machine = builder.build()(object())
machine.finish()

Python StateMachine

Defines declarative state machines and statecharts for synchronous and asynchronous Python.

Downloads / mo
3.2M
Stars
1.3K
Last release
3.2.2
License
MIT

Strengths

  • Declares workflows as Python classes. Express states, transitions, and guards together in a machine class.
  • Detects async callbacks automatically. Use the same event API with an automatically selected async engine.

Limitations

  • Thread sharing needs synchronization. Protect a shared machine instance when callbacks run across multiple threads.

Quickstart

From README.md
$ pip install python-statemachine
from statemachine import StateChart, State

class Switch(StateChart):
    off = State(initial=True)
    on = State()
    turn_on = off.to(on)

switch = Switch()
switch.send('turn_on')

Python StateMachine examples

From open-source projects on GitHub

Defines object-oriented finite state machines with optional extension classes.

Downloads / mo
2.0M
Stars
6.6K
Last release
0.9.3
License
MIT

Strengths

  • Binds transitions to existing models. Attach states, triggers, and callbacks to application objects.
  • Combines hierarchy and async callbacks. Choose the matching machine extension for nested states and asynchronous processing.

Limitations

  • Queued success means accepted. A queued trigger returns True before its eventual transition outcome is known.

Quickstart

From README.md
$ pip install transitions
from transitions import Machine
machine = Machine(states=['a', 'b'], initial='a')
machine.add_transition('advance', 'a', 'b')
machine.advance()

transitions examples

From open-source projects on GitHub

Django FSM-2

Adds finite state machine support to Django.

Downloads / mo
668.6K
Stars
287
Last release
4.3.0
License
MIT

Quickstart

From README.md
$ pip install django-fsm-2
from django.db import models
from django_fsm import FSMField, FSMModelMixin, transition

class Article(FSMModelMixin, models.Model):
    state = FSMField(default='draft')
    @transition(field=state, source='draft', target='published')
    def publish(self):
        pass

article = Article()
article.publish()

Django FSM

Adds state machines to Python objects and Django models.

Downloads / mo
553.8K
Stars
2.3K
Last release
5.0.2
License
AGPL-3.0-or-later WITH viewflow-library-exception

Quickstart

From README.rst
$ pip install django-fsm
from django_fsm import State

class Review:
    state = State(states=None, default='draft')
    @state.transition(source='draft', target='published')
    def publish(self):
        pass

review = Review()
review.publish()

Implements finite state machines in Python.

Downloads / mo
91.8K
Stars
398
Last release
2.1.6
License
MIT

Quickstart

From README.rst
$ pip install fysom
from fysom import Fysom
fsm = Fysom(initial='green', events=[('warn', 'green', 'yellow')])
fsm.warn()

fysom examples

From open-source projects on GitHub

Provides developer-friendly state machines for Python.

Downloads / mo
90.2K
Stars
62
Last release
3.5.0
License
Apache-2.0

Strengths

  • Separates events from reaction execution. Drive events explicitly or use a runner for callback-driven transitions.
  • Supports hierarchical machines. Compose nested finite machines for hierarchical state processing.

Limitations

  • Frozen definitions reject additions. Finish adding states, transitions, and reactions before freezing the machine.

Quickstart

From examples.rst
$ pip install automaton
from automaton.machines import FiniteMachine
machine = FiniteMachine()
machine.add_state('a')
machine.add_state('b')
machine.add_transition('a', 'b', 'advance')
machine.initialize(start_state='a')
machine.process_event('advance')

Automaton examples

From open-source projects on GitHub

Interprets and checks statechart models.

Downloads / mo
6.6K
Stars
172
Last release
1.6.14
License
LGPL-3.0

Quickstart

From io.html
$ pip install sismic
from sismic.io import import_from_yaml
from sismic.interpreter import Interpreter

chart = import_from_yaml('''statechart:
  name: Example
  root state:
    name: root
    initial: idle
    states:
      - name: idle
''')
interpreter = Interpreter(chart)
interpreter.execute()

FAQ

Python StateMachine suits workflows with compound states, parallel regions, and async callbacks. transitions suits object-oriented machines with hierarchy, asyncio, and diagram extensions. Django FSM suits state fields on Django models.

transitions provides asynchronous machine extensions. Python StateMachine selects its async engine automatically when async callbacks are registered.

Python StateMachine requires external synchronization for an instance shared across threads.

Yes. Python StateMachine diagrams require pydot and the Graphviz tool. Automat image generation also requires Graphviz.

For coding agents

Found your state machine library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official