django-pgtrigger
Postgres trigger support integrated with Django models.
Decision gist · record as of 2026-08-14
Yes, if you use PostgreSQL and Django together. The package is well-maintained, has no known vulnerabilities, and solves real problems—constraints and state enforcement—more reliably at the database level than in application code. The aging maintenance status is not a blocker; the repository is active and the package is stable. Install it when you need database-level triggers; skip it if you use a different database backend.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires PostgreSQL as the database backend; django-pgtrigger does not work with other database engines.
- Low friction: pure Python wheel with only django as a runtime dependency.
- Maintenance status is aging—last release 253 days ago—but the repository remains active with recent commits and no archived status.
License · maintenance · safety
BSD-3-Clause (permissive) — BSD-3-Clause is permissive; you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
last release 2025-12-04 (253 days) · last repo commit 2025-12-04 · 644 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,525,527 downloads/mo, #3,815 on PyPI
Alternatives
Verify before relying
pip install django-pgtrigger
# Add 'pgtrigger' to settings.INSTALLED_APPS
import pgtrigger
from django.db import models
class ProtectedModel(models.Model):
class Meta:
triggers = [
pgtrigger.Protect(name="protect_deletes", operation=pgtrigger.Delete)
]
# Run: python manage.py makemigrations && python manage.py migrate- Performance characteristics when triggers fire on high-volume tables or complex multi-field conditions.
- Compatibility guarantees across the stated Postgres 14–18 range in production environments.
- Whether all common use cases can be expressed without writing raw SQL.
What it is and what it does
django-pgtrigger is a Django integration layer for PostgreSQL triggers. It lets you declare triggers as Python objects in your model's Meta class—such as Protect, ReadOnly, SoftDelete, or FSM—and have them automatically created and managed through Django migrations. Instead of writing raw SQL or relying on Django signals and application logic, you define what should happen at the database level when rows are inserted, updated, or deleted, with optional conditions based on old and new row values.
The package handles the translation from Python trigger definitions to SQL, manages migrations, and provides utilities like pgtrigger.Q and pgtrigger.F to express row conditions without raw SQL. It supports Python 3.10–3.14 and Django 4.2–6.0, and requires PostgreSQL as the database backend. Most use cases avoid custom SQL entirely, though the package allows it for complex scenarios.
Use it for
- Prevent deletion of active records or enforce soft-delete behavior at the database level.
- Make specific model fields or entire models read-only after creation without application-layer checks.
- Enforce state transitions (e.g., workflow statuses) so invalid transitions are rejected by the database.
- Automatically update search vectors or denormalized columns whenever source data changes.
- Ensure official interfaces are used (e.g., force User.objects.create_user over User.objects.create).
- Track or snapshot model changes for audit logs or versioning without signal handlers.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you use PostgreSQL and Django together.
The package is well-maintained, has no known vulnerabilities, and solves real problems—constraints and state enforcement—more reliably at the database level than in application code. The aging maintenance status is not a blocker; the repository is active and the package is stable. Install it when you need database-level triggers; skip it if you use a different database backend.
Install
django-pgtrigger on PyPI
Before you install
Low friction: pure Python wheel with only django as a runtime dependency. Maintenance status is aging—last release 253 days ago—but the repository remains active with recent commits and no archived status.
Requires PostgreSQL as the database backend; django-pgtrigger does not work with other database engines.
License in practice
BSD-3-Clause is permissive; you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install django-pgtrigger
# Add 'pgtrigger' to settings.INSTALLED_APPS
import pgtrigger
from django.db import models
class ProtectedModel(models.Model):
class Meta:
triggers = [
pgtrigger.Protect(name="protect_deletes", operation=pgtrigger.Delete)
]
# Run: python manage.py makemigrations && python manage.py migrate
Verify before relying
- Performance characteristics when triggers fire on high-volume tables or complex multi-field conditions.
- Compatibility guarantees across the stated Postgres 14–18 range in production environments.
- Whether all common use cases can be expressed without writing raw SQL.
Package facts
| License | BSD-3-Clause permissive |
| Python support | Supports the current Python release <4,>=3.10.0 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagedjango |
| Maintenance | Aging 253 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,525,527 / month, #3,815 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Framework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14 |
Evidence: django_pgtrigger-4.17.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “postgres triggers django”
- django-pgtriggerdjango-pgtrigger lets you define PostgreSQL triggers declaratively on…
- django-pghistoryTracks all changes to Django models using PostgreSQL triggers,…
- django-pgviews-reduxAdds first-class PostgreSQL view support to Django's ORM, allowing…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also django-pghistory · django-read-only · django-postgres-extra · django-pgviews-redux · alembic_utils · django-postgres-copy · django-pgmigrate · django-soft-delete · django-pg-migration-tools · django-fsm-log