skillfed

django-lifecycle

Declarative model lifecycle hooks.

django-lifecycle v1.3.0 257.8K downloads/30d#8,434 on PyPI1,405
Permissive license MIT Active released

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-lifecycle

uv

uv add django-lifecycle

poetry

poetry add django-lifecycle

Installing 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

Development Status :: 4 - BetaFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.2Framework :: Django :: 6.0License :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

django model lifecycle hooksdjango before after save hooksdjango model callbacksdjango lifecycle decoratordjango model event hooksdjango conditional model hooks
django-modelslifecycle-hooksorm-utilities

More Application Frameworks packages

fastapi

FastAPI is a Python web framework for building…

permissive · top 100 on PyPI

annotated-doc

Provides a way to document function parameters,…

permissive · top 100 on PyPI

textual

Textual is a Python framework for building…

permissive · top 100 on PyPI

typer

Typer builds command-line applications from…

permissive · top 1,000 on PyPI

mcp

Build and connect to Model Context Protocol…

permissive · top 1,000 on PyPI

Werkzeug

Werkzeug is a WSGI utility library providing…

permissive · top 1,000 on PyPI

django-dirtyfields

Tracks which fields on a Django model instance…

permissive · top 15,000 on PyPI

django-signal-webhooks

Adds webhook support to Django models by…

permissive · top 15,000 on PyPI

snapshot-restore-py

Registers runtime hooks in AWS Lambda…

permissive · top 5,000 on PyPI

django-fsm-2

Adds declarative finite state machine support…

permissive · top 15,000 on PyPI

django-click

Wraps the click command-line library to let you…

permissive · top 15,000 on PyPI

django-upgrade

Automatically modernizes Django project code by…

permissive · top 15,000 on PyPI

django-fsm-log

Automatically logs state transitions for Django…

permissive · top 15,000 on PyPI

django-ordered-model

Adds ordering and reordering capabilities to…

permissive · top 15,000 on PyPI

django-waffle

Django Waffle provides feature flags (toggles)…

permissive · top 5,000 on PyPI

django-admin-extra-buttons

Adds custom buttons, links, and views to Django…

permissive · top 15,000 on PyPI