django-perf-rec
Keep detailed records of the performance of your Django code.
What it is and what it does
django-perf-rec is a test instrumentation tool that records all database queries and cache operations executed within a test context, storing them in a YAML file for comparison on subsequent runs. When a test runs again, the new operations are compared against the stored record; if they differ, the test fails, alerting you to performance regressions. The tool fingerprints queries and cache keys by replacing variable data (like primary keys) with `#` and truncating long strings with `...`, so that incidental changes like new columns or different random data don't cause spurious test failures.
It wraps Django's lower-level `assertNumQueries` with a much richer view of what actually happened during test execution. You use it as a context manager around the code you want to profile, and it automatically determines the test name and file path for storing records. The package also provides hooks to selectively capture tracebacks for debugging specific operations and to filter which operations get recorded, useful for hiding test-only queries that would be handled differently in production.
Use it for:
- Catch unintended N+1 queries introduced by code changes before they reach production.
- Document expected database and cache behavior for a test as a regression baseline.
- Debug which code paths trigger specific database queries using optional traceback capture.
- Exclude test-only database operations from performance records using operation filters.
- Enforce consistent query patterns across a Django test suite without manual assertion counts.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Records and compares Django database queries and cache operations in tests, detecting performance regressions by storing fingerprinted operation logs in YAML files.
Yes, if you maintain a Django test suite and want to detect performance regressions automatically. The low install friction, permissive license, and active maintenance make it a practical choice. Note that the author recommends inline-snapshot-django as a faster alternative for new projects, so consider whether that better fits your needs; django-perf-rec remains suitable for existing codebases and will continue to receive maintenance.
Install
django-perf-rec on PyPI
pip
pip install django-perf-recuv
uv add django-perf-recpoetry
poetry add django-perf-recInstalling django-perf-rec
Before you install
Low friction install with three stable runtime dependencies (django, pyyaml, sqlparse). Package is actively maintained and in use, though the author notes it is now in maintenance mode with a newer alternative (inline-snapshot-django) available.
License in practice
MIT license permits commercial and private use with minimal restrictions—suitable for most projects.
Quickstart
pip install django-perf-rec
import django_perf_rec
with django_perf_rec.record():
self.client.get("/")
Requires Django 4.2 to 6.0 and Python 3.9 or later; intended for use within Django test cases.
Verify before relying
- Performance overhead of recording and fingerprinting operations during test runs.
- Compatibility with test runners other than Django's default (pytest support mentioned but not detailed).
- How YAML file diffs are presented and whether they integrate with CI/CD systems.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — django, pyyaml, sqlparse |
| Maintenance | actively maintained — 330 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 100,108/month — #13,002 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_perf_rec-4.31.0-py3-none-any.whl
Keywords: Django
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
django-dirtyfieldsTracks which fields on a Django model instance…
permissive · top 15,000 on PyPI
django-querycountDjango middleware that logs the number of…
permissive · top 15,000 on PyPI
django-zealDetects N+1 query problems in Django…
unclear · top 15,000 on PyPI
django-mock-queriesMocks Django QuerySet operations in memory for…
permissive · top 15,000 on PyPI
django-queryinspectDjango middleware that logs and reports SQL…
permissive · top 15,000 on PyPI
django-cacheopsAutomatic and manual ORM query caching for…
permissive · top 5,000 on PyPI
betamaxBetamax records and replays HTTP interactions…
permissive · top 15,000 on PyPI
django-upgradeAutomatically modernizes Django project code by…
permissive · top 15,000 on PyPI
django-cachalotAutomatically caches Django ORM queries and…
permissive · top 15,000 on PyPI
recordsRecords provides a lightweight SQL query…
permissive · top 15,000 on PyPI