Skip to main content

django_nplusone

Discover possible N+1 queries in Django ORM at runtime

The objective of this library is to help you discover any N+1s in your code at development time. Enable logging of warnings by following instructions shown in Usage section. Run your Django app as usual and you will see warning logs of any possible N+1s if found.

Installation

Install the package from PyPI using pip as following

pip install django_nplusone

Usage

Once package is installed, you can register the package in your settings.py as:

import nplusone

if DEBUG:
    nplusone.show_nplusones()

This should start logging possible N+1s warnings using your logger configuration. The library uses standard python logging module and uses logger by the name of nplusone.

Ignore specific warnings

You can ignore warning for a specific statement by ending the statement with # NO-NPLUSONE.

Test

You can test the N+1 warning logging by putting some code as shown below somewhere in your application code that you know will get executed. Say you have a model User with a foreign key field org to Organization model.

user = User.objects.all()[0]
print(user.org)

You should see a log message with a message that looks like this:

... Possible N+1 for model: User, field: org, relationship: ForwardManyToOne, file: <?>, function: <?>, line: <?>, statement: <?>

where <?> will have correct values for the fields derived from call stack pointing you to the statement that has possible N+1

Metadata

Release files for django-nplusone 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-nplusone 0.0.5
File Size Uploaded Provenance Actions
django_nplusone-0.0.5.tar.gz 4.3 kB Without provenance Details for django_nplusone-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-nplusone 0.0.5
File Interpreter ABI Platform Actions
django_nplusone-0.0.5-py2-none-any.whl Python 2 none any Details for django_nplusone-0.0.5-py2-none-any.whl

Total release size: 9.7 kB

Release files / django_nplusone-0.0.5.tar.gz

Download URL django_nplusone-0.0.5.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1a35e7755e7ba020aadd53e20489261ea35c2299fc3f50a4942732e623f672d9
BLAKE2b-256 checksum
How to use checksums
4c8a9c57192bc5028bc345fab209dd5957431bb4ad3c6b2698382ce659abc699
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/2.7.5

Release files / django_nplusone-0.0.5-py2-none-any.whl

Download URL django_nplusone-0.0.5-py2-none-any.whl
Size 5.5 kB
Tags Python 2
SHA-256 checksum
How to use checksums
09c01b47331118b503fb3cf6d65aa13cd3fec006a2602752c12640c2df994bd3
BLAKE2b-256 checksum
How to use checksums
802f462d78024c63b8ce38efcfdd4d3526853cf7b61d3eca50396d93abd6d276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/2.7.5

Security for django-nplusone 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page