Skip to main content

DB utility to help you catch query inefficiencies in Django.

Project description

This is a simple implementation of the django_query_analyze function detailed in The Django Speed Handbook: making a Django app faster, featured in the Django newsletter a few weeks back.

The idea is that you can wrap you pure db-query functions with a decorator, and make sure the function is calling the database as you expect it to.

from django_qc import db_helper
from app.models import Song

def get_songs():
    return serialize_songs(Song.objects.all(), many=True)

See the original article for a more thorough description of the issue.

Since the Django ORM is lazy, you will likely want to wrap your serializers rather than your queries, if they’re not in the same function. For example:

from django_qc import db_helper

def serialize_songs(song: Song)
    return {

This package should only run during development.


Install using pip:

pip install django-qc


There are three settings that can be configured:

    'RAISE_EXC': True,
    'LOG_EXC': True,

    Whether or not to raise an error when the specified query count deviates the actual query count.

    Default: True


    Whether or not to log an exception (logger.exception) when the specified query count deviates the actual query count. If you’re using Sentry or similar tools, an exception logger will raise an issue in the system. This only applies to when RAISE_EXC is False.

    Default: True


    Whether or not to check query counts at runtime.

    Default: True

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-qc, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size django_qc-0.2.2-py3-none-any.whl (10.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-qc-0.2.2.tar.gz (8.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page