django-querycount
Middleware that Prints the number of DB queries to the runserver console.
What it is and what it does
django-querycount is a Django middleware that intercepts HTTP requests during development and logs how many database queries were executed to handle each request. It prints colored, threshold-based output to the runserver console, helping developers spot performance issues early. The middleware is hardcoded to work only when DEBUG is True, making it safe for development-only use.
The package offers configurable thresholds to color-code query counts (MEDIUM at 50, HIGH at 200), regex-based request and SQL pattern filtering to ignore certain paths or query types, optional duplicate query reporting, and a custom response header containing the query count. It has no runtime dependencies and integrates purely through Django's middleware stack.
Use it for:
- Identify query problems during local development by monitoring query counts per request.
- Compare query efficiency across different request handlers to spot performance issues.
- Filter out noisy middleware (e.g., health checks, admin requests) to focus on application endpoints.
- Track duplicate queries to find repeated database calls that could be optimized.
- Add query count metadata to HTTP response headers for integration with monitoring tools.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Django middleware that logs the number of database queries executed for each HTTP request in the runserver console, with configurable thresholds and filtering.
Yes, if you are actively developing a Django application and want low-friction query profiling during local testing. The permissive MIT license and zero runtime dependencies make it easy to add. However, maintenance is dormant (last release 2023-01-05); verify compatibility with your Django and Python versions before relying on it. The high install friction is offset by the simplicity of the middleware pattern.
Install
django-querycount on PyPI
pip
pip install django-querycountuv
uv add django-querycountpoetry
poetry add django-querycountInstalling django-querycount
Before you install
High install friction with no runtime dependencies but requires manual middleware registration in Django settings. Maintenance is dormant—last release was 2023-01-05, though the repository remains active with a recent commit on 2024-05-29 and 408 stars. Use only if you accept infrequent updates.
License in practice
MIT license (permissive) allows free use, modification, and distribution with minimal restrictions. No licensing barrier to adoption.
Quickstart
pip install django-querycount
# In Django settings.py, add to MIDDLEWARE:
MIDDLEWARE = [
'querycount.middleware.QueryCountMiddleware',
# ...
]
# Optional: configure thresholds
QUERYCOUNT = {
'THRESHOLDS': {'MEDIUM': 50, 'HIGH': 200}
}
Requires Django project with DEBUG=True; middleware must be manually registered in MIDDLEWARE setting.
Verify before relying
- Compatibility with current Django versions relative to the 2023-01-05 release date.
- Whether the package works with modern Python versions beyond what the fact sheet specifies.
- Whether high install friction reflects a known blocker or is typical for middleware packages.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 1,317 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 153,337/month — #10,883 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django-querycount-0.8.3.tar.gz
Keywords: django, querycount, database, performance
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
django-queryinspectDjango middleware that logs and reports SQL…
permissive · top 15,000 on PyPI
requests-trackerA Django development middleware that collects…
permissive · top 15,000 on PyPI
django-zealDetects N+1 query problems in Django…
unclear · top 15,000 on PyPI
django-silkSilk intercepts and profiles HTTP requests,…
permissive · top 5,000 on PyPI
drf-api-loggerCaptures and logs Django REST Framework API…
permissive · top 15,000 on PyPI
django-perf-recRecords and compares Django database queries…
permissive · top 15,000 on PyPI
django-maintenance-modeActivates a 503 maintenance page in Django…
permissive · top 15,000 on PyPI
sqltapsqltap hooks into SQLAlchemy to collect and…
permissive · top 15,000 on PyPI
django-sql-explorerA Django-based SQL query editor and business…
permissive · top 15,000 on PyPI
pygountPygount counts source lines of code (SLOC)…
permissive · top 15,000 on PyPI