django-pghistory
History tracking for Django and Postgres
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has low install friction, carries a permissive license, and solves a real problem—reliable audit trails without application code changes. It's well-suited for Django projects using PostgreSQL where compliance, debugging, or recovery capabilities matter. No known security vulnerabilities. Primary constraint is PostgreSQL dependency; it will not work with other databases.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires PostgreSQL and Django; add pghistory and pgtrigger to INSTALLED_APPS after installation.
- Low friction install with a pure-Python wheel.
- Actively maintained as of 2026-02-17 with 540 repository stars.
License · maintenance · safety
BSD-3-Clause (permissive) — BSD-3-Clause permissive license allows commercial and private use with minimal restrictions.
last release 2026-02-17 (178 days) · last repo commit 2026-02-17 · 540 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 783,657 downloads/mo, #5,074 on PyPI
Alternatives
Verify before relying
pip install django-pghistory
import pghistory
from django.db import models
@pghistory.track()
class TrackedModel(models.Model):
int_field = models.IntegerField()
text_field = models.TextField()
m = TrackedModel.objects.create(int_field=1, text_field="hello")
m.int_field = 2
m.save()
print(m.events.values("pgh_obj", "int_field"))- Whether the package's trigger-based approach has measurable performance impact on high-volume write workloads
- How context attachment and metadata storage scale with concurrent application instances
What it is and what it does
django-pghistory is a Django package that automatically records every change to your models by installing PostgreSQL triggers on the underlying tables. Instead of instrumenting your application code, it captures inserts, updates, and bulk operations—even raw SQL changes—at the database level and stores them in dynamically-created event models that mirror your original model's fields. You decorate a model with `@pghistory.track()`, run migrations, and the system handles the rest: every modification is logged with metadata fields like `pgh_obj` (the tracked object ID) and timestamps.
The package includes admin integration and middleware for attaching application context (such as the logged-in user) to events without extra database queries. It supports selective field tracking, conditional event storage based on field transitions, and aggregation across multiple event models. Since it relies on PostgreSQL triggers rather than application-level hooks, it captures changes regardless of how they reach the database—ORM saves, bulk updates, or direct SQL all get tracked.
Use it for
- Audit compliance: maintain a tamper-resistant record of all model changes for regulatory requirements.
- Soft deletes and recovery: revert models to previous versions or implement logical deletion with full history.
- User activity tracking: attach context like user ID to each change for accountability and debugging.
- Data debugging: trace the sequence of field changes to diagnose unexpected model states.
- Bulk operation auditing: capture changes from bulk operations or raw SQL that ORM hooks would miss.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has low install friction, carries a permissive license, and solves a real problem—reliable audit trails without application code changes. It's well-suited for Django projects using PostgreSQL where compliance, debugging, or recovery capabilities matter. No known security vulnerabilities. Primary constraint is PostgreSQL dependency; it will not work with other databases.
Install
django-pghistory on PyPI
Before you install
Low friction install with a pure-Python wheel. Actively maintained as of 2026-02-17 with 540 repository stars. Requires only django and django-pgtrigger as runtime dependencies.
Requires PostgreSQL and Django; add pghistory and pgtrigger to INSTALLED_APPS after installation.
License in practice
BSD-3-Clause permissive license allows commercial and private use with minimal restrictions.
Quickstart
pip install django-pghistory
import pghistory
from django.db import models
@pghistory.track()
class TrackedModel(models.Model):
int_field = models.IntegerField()
text_field = models.TextField()
m = TrackedModel.objects.create(int_field=1, text_field="hello")
m.int_field = 2
m.save()
print(m.events.values("pgh_obj", "int_field"))
Verify before relying
- Whether the package's trigger-based approach has measurable performance impact on high-volume write workloads
- How context attachment and metadata storage scale with concurrent application instances
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 | 2 packagesdjangodjango-pgtrigger |
| Maintenance | Actively maintained 178 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 783,657 / month, #5,074 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_pghistory-3.9.2-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 audit trail”
- django-pghistoryTracks all changes to Django models using PostgreSQL triggers,…
- ciris-persistCIRISPersist provides unified, versioned storage for CIRIS federation…
- pycadfPyCADF implements the Cloud Auditing Data Federation specification to…
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-easy-audit · django-pgtrigger · django-auditlog · django-reversion · django-dirtyfields · SQLAlchemy-Continuum · django-postgres-copy · django-crum · django-fsm-log · django-pgactivity