django-fsm-2
Django friendly finite state machine support.
What it is and what it does
Django FSM-2 is a maintained fork of the archived Django FSM project that brings finite state machine patterns to Django models. Instead of storing state as a plain CharField and managing transitions scattered throughout your codebase, you declare states and transitions once using decorators on model methods. This centralizes your model's lifecycle logic in one place, making it easier to reason about valid state changes, enforce preconditions, and attach business logic (side effects, permissions, notifications) to specific transitions.
The package works by providing FSMField (or FSMIntegerField/FSMKeyField variants) to store state, the @transition decorator to define allowed state changes, and helper methods to check permissions and available transitions. Transition methods can contain arbitrary logic; the state changes in memory on success, and you persist it with save(). You can restrict transitions with conditions, attach permissions, specify error-handling states, and use dynamic target states based on method return values.
Use it for:
- Managing blog post lifecycle (draft → review → published → archived) with automatic permission and timing checks.
- Enforcing order state workflows (pending → processing → shipped → delivered) with side effects like notifications.
- Controlling document approval flows where transitions require specific user permissions and conditions.
- Building task or ticket systems where state changes trigger notifications or log entries.
- Implementing subscription or account status transitions with business logic tied to each change.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds declarative finite state machine support to Django models, letting you define state transitions once with decorators instead of managing state values manually throughout your code.
Yes. This is a well-maintained, actively developed fork of a proven library with no known vulnerabilities, low install friction, and clear production-stable status. Use it if you need to manage model state transitions declaratively in Django; it eliminates scattered state-management code and makes workflows explicit and testable.
Install
django-fsm-2 on PyPI
pip
pip install django-fsm-2uv
uv add django-fsm-2poetry
poetry add django-fsm-2Installing django-fsm-2
Before you install
Low friction install with only three runtime dependencies (django, django-stubs-ext, typing-extensions). The package is actively maintained with a recent commit on 2026-08-07 and marked as Production/Stable.
License in practice
MIT license (permissive) means you can use this freely in commercial and private projects with minimal restrictions.
Quickstart
pip install django-fsm-2
from django_fsm import FSMField, FSMModelMixin, transition
class BlogPost(FSMModelMixin, models.Model):
state = FSMField(default='new')
@transition(field=state, source='new', target='published')
def publish(self, **kwargs):
pass
post = BlogPost.objects.get(pk=1)
post.publish()
post.save()
Requires Python 3.10 or later and Django 4.2 or later.
Verify before relying
- Whether typing support is fully implemented or still planned as mentioned in the description.
- Performance characteristics when managing models with many possible state transitions.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — django-stubs-ext, django, typing-extensions |
| Maintenance | actively maintained — 151 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 437,224/month — #6,671 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_fsm_2-4.2.4-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
automatonAutomaton provides state machine classes and…
permissive · top 15,000 on PyPI
django-fsmProvides finite state machine support for…
permissive · top 15,000 on PyPI
django-fsm-logAutomatically logs state transitions for Django…
permissive · top 15,000 on PyPI
django-lifecycleAdds declarative lifecycle hooks to Django…
permissive · top 15,000 on PyPI
python-statemachineDefines finite state machines and statecharts…
permissive · top 5,000 on PyPI
fysomFysom is a finite state machine library that…
permissive · top 15,000 on PyPI
transitionsTransitions is a lightweight state machine…
permissive · top 5,000 on PyPI
django-pgtriggerdjango-pgtrigger lets you define PostgreSQL…
permissive · top 5,000 on PyPI
AutomatAutomat provides a Python library for building…
permissive · top 5,000 on PyPI
django-concurrencyAdds optimistic locking to Django models to…
permissive · top 15,000 on PyPI