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
@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
Built Distribution
File details
Details for the file django-qc-0.0.1.tar.gz
.
File metadata
- Download URL: django-qc-0.0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1587e770c14be131b4dbe426293b769aae5d861ffeff70abb46e6d16caade1a4 |
|
MD5 | 68c7fa862fff2f6709d119255cda7904 |
|
BLAKE2b-256 | 2750a08532b415a5c4ebe963ee0261dc0bec3c00d0ffda61bc1cfe16f7a2f499 |
Provenance
File details
Details for the file django_qc-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_qc-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 690ff0e4258ccb283b966aa46726f8452df71b7df3ded8fa20b7002f925c1372 |
|
MD5 | bf36fead25d2ad7e631eb169625195cb |
|
BLAKE2b-256 | 04b69be8ac199406a9c6e7bfd54aa01e2d08bede4943c01cb00a3f75b057345a |