Skip to main content

DB utility to help you catch query inefficiencies in Django.

Project description

https://img.shields.io/pypi/v/django-qc.svg https://img.shields.io/pypi/pyversions/django-qc.svg https://img.shields.io/pypi/djversions/django-qc.svg https://codecov.io/gh/sondrelg/django-query-counter/branch/master/graph/badge.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white

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

@db_helper(count=1)
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

@db_helper(count=1)
def serialize_songs(song: Song)
    return {
        'name': song.name,
        'cd': song.cd.name,
    }

This package should only run during development.

Installation

Install using pip:

pip install django-qc

Settings

There are three settings that can be configured:

DB_HELPER {
    'RAISE_EXC': True,
    'LOG_EXC': True,
    'DEBUG': DEBUG
}
  • RAISE_EXC

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

    Default: True

  • LOG_EXC

    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

  • DEBUG

    Whether or not to check query counts at runtime.

    Default: True

Project details


Download files

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

Source Distribution

django-qc-0.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

django_qc-0.2.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file django-qc-0.2.0.tar.gz.

File metadata

  • Download URL: django-qc-0.2.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for django-qc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4de445e85611269844a4aa20c71244a3b603e35edf57f1f2f149cd406087a9ab
MD5 5c720a5fd73d6790aa5c391c02f7e88d
BLAKE2b-256 9c38009908156ae7bd22f1b1e8ebd949bcec3007cad4726f1fe351cbd6453d37

See more details on using hashes here.

Provenance

File details

Details for the file django_qc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_qc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for django_qc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73ef7c1372e933514100e832edf1ebf2e55401617edd0774f826d31558583b59
MD5 7b17a615e1460bef73a85bc997563f84
BLAKE2b-256 f6ef0f5da3c82e92969fede283818bdddabf8aebe21d2e9795d7e92292ffb33f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page