skillfed

django-querycount

Middleware that Prints the number of DB queries to the runserver console.

django-querycount v0.8.3 153.3K downloads/30d#10,883 on PyPI408
Permissive license MIT DORMANT released

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

uv

uv add django-querycount

poetry

poetry add django-querycount

Installing 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

Development Status :: 4 - BetaEnvironment :: Web EnvironmentFramework :: DjangoIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonTopic :: Utilities

Tags

django query count loggingdatabase query profiling middlewaredjango debug query counterdb query monitoring djangodjango performance query trackingrequest query statistics djangodjango sql query debugging
django-middlewarequery-profilingdevelopment-tool

More Utilities packages