django-lifecycle
Declarative model lifecycle hooks.
What it is and what it does
Django Lifecycle Hooks provides a decorator-based alternative to Django Signals for attaching code to model lifecycle events. Instead of overriding save() or __init__ and manually tracking field changes, you decorate methods with @hook and specify when they should run (before/after create, update, or delete) and under what conditions. The package includes a LifecycleModel base class and condition helpers like WhenFieldHasChanged and WhenFieldValueIs to express complex logic declaratively.
The main appeal is readability and maintainability: lifecycle logic stays close to the model definition rather than scattered across signal handlers. It works with Django 4.2, 5.0, 5.2, and 6.0, and supports Python 3.8 through 3.14. The package has been in active development since 2018 and carries no known security vulnerabilities.
Use it for:
- Automatically update a timestamp field whenever a model's content changes, without overriding save().
- Trigger side effects (like sending emails) only when a model transitions between specific states (e.g., draft to published).
- Run validation or cleanup logic before or after a model is created, updated, or deleted, with fine-grained conditions.
- Track field changes and react to them in the same model class, keeping related logic together and readable.
- Replace Signal handlers for simple lifecycle events when you want less indirection and clearer code flow.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds declarative lifecycle hooks to Django models via a @hook decorator, letting you run code at specific model events (before/after create, update, delete) without overriding save() or using Signals.
Yes. The package is actively maintained, has low install friction, carries no known vulnerabilities, and solves a real readability problem in Django projects. It's a straightforward drop-in for teams that find Signals cumbersome and prefer declarative, co-located lifecycle logic. The MIT license imposes no restrictions.
Install
django-lifecycle on PyPI
pip
pip install django-lifecycleuv
uv add django-lifecyclepoetry
poetry add django-lifecycleInstalling django-lifecycle
Before you install
Low friction install with a single runtime dependency (Django). Active maintenance as of 2026-06-14 with 1405 repository stars and recent releases.
License in practice
MIT license (permissive) — you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
Quickstart
pip install django-lifecycle
from django_lifecycle import LifecycleModel, hook, BEFORE_UPDATE
from django_lifecycle.conditions import WhenFieldHasChanged
class Article(LifecycleModel):
contents = models.TextField()
updated_at = models.DateTimeField(null=True)
@hook(BEFORE_UPDATE, WhenFieldHasChanged("contents", has_changed=True))
def on_content_change(self):
self.updated_at = timezone.now()
Verify before relying
- Whether the package supports Python 3.14 as a stable release or only as a pre-release target
- Whether Django 6.0 is currently released or a future version target
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — Django |
| Maintenance | actively maintained — 61 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 257,820/month — #8,434 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_lifecycle-1.3.0-py3-none-any.whl
Keywords: django, model, lifecycle, hooks, callbacks
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
django-dirtyfieldsTracks which fields on a Django model instance…
permissive · top 15,000 on PyPI
django-signal-webhooksAdds webhook support to Django models by…
permissive · top 15,000 on PyPI
snapshot-restore-pyRegisters runtime hooks in AWS Lambda…
permissive · top 5,000 on PyPI
django-fsm-2Adds declarative finite state machine support…
permissive · top 15,000 on PyPI
django-clickWraps the click command-line library to let you…
permissive · top 15,000 on PyPI
django-upgradeAutomatically modernizes Django project code by…
permissive · top 15,000 on PyPI
django-fsm-logAutomatically logs state transitions for Django…
permissive · top 15,000 on PyPI
django-ordered-modelAdds ordering and reordering capabilities to…
permissive · top 15,000 on PyPI
django-waffleDjango Waffle provides feature flags (toggles)…
permissive · top 5,000 on PyPI
django-admin-extra-buttonsAdds custom buttons, links, and views to Django…
permissive · top 15,000 on PyPI