N+1 query detection for Django
Project description
django-nplus1
N+1 query detection for Django.
Detects N+1 queries (lazy loading related objects in a loop) and unused eager loads (select_related/prefetch_related that are never accessed) in your Django application.
Modernized fork of nplusone, stripped down to Django-only support with Python 3.12+ / Django 5.2+.
Features
- N+1 detection: Warns when a related object is lazily loaded on an instance that was part of a bulk query
- Unused eager load detection: Warns when
select_relatedorprefetch_relatedresults are never accessed - Middleware: Automatically monitors all requests
- pytest plugin:
nplus1fixture and@pytest.mark.nplus1marker for test-time detection - Profiler: Context manager for manual use in scripts or tests
- Whitelisting: Ignore specific model/field combinations with wildcard support
- Zero dependencies: Only requires Django (no blinker, no six)
Quick Start
pip install django-nplus1
# settings.py
INSTALLED_APPS = [
...,
"django_nplus1",
]
MIDDLEWARE = [
...,
"django_nplus1.NPlusOneMiddleware",
]
# Optional
NPLUS1_RAISE = True # Raise exceptions instead of logging (recommended for tests)
Documentation
Full documentation at oliverhaas.github.io/django-nplus1.
License
MIT
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_nplus1-0.1.0a1.tar.gz.
File metadata
- Download URL: django_nplus1-0.1.0a1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9da6b2526d71e20c5feaad46f0fceb77ede2ec3f64c7ce8a3418fbc92ef247a0
|
|
| MD5 |
091fdf40605c8b3583fee9bd602d30be
|
|
| BLAKE2b-256 |
0a5cb08dd4d60dcc680042a5abd74a2f593af32e486e02a70a5d4ebfb2631b6e
|
Provenance
The following attestation bundles were made for django_nplus1-0.1.0a1.tar.gz:
Publisher:
publish.yml on oliverhaas/django-nplus1
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_nplus1-0.1.0a1.tar.gz -
Subject digest:
9da6b2526d71e20c5feaad46f0fceb77ede2ec3f64c7ce8a3418fbc92ef247a0 - Sigstore transparency entry: 1238620095
- Sigstore integration time:
-
Permalink:
oliverhaas/django-nplus1@02e6e35643c009d5f88220692edfbc6b806207b1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/oliverhaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@02e6e35643c009d5f88220692edfbc6b806207b1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file django_nplus1-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: django_nplus1-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8790088b31a633779b8800f95fbf7066fa0a7c2b5cfa939ae9267b76dca9a6bc
|
|
| MD5 |
2d159b0e7b49878fde46bafc5e0c06a8
|
|
| BLAKE2b-256 |
ee11cb5e94373ff81538415c292066785c3ab9996330c5dd6412df7d21bf5c36
|
Provenance
The following attestation bundles were made for django_nplus1-0.1.0a1-py3-none-any.whl:
Publisher:
publish.yml on oliverhaas/django-nplus1
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_nplus1-0.1.0a1-py3-none-any.whl -
Subject digest:
8790088b31a633779b8800f95fbf7066fa0a7c2b5cfa939ae9267b76dca9a6bc - Sigstore transparency entry: 1238620098
- Sigstore integration time:
-
Permalink:
oliverhaas/django-nplus1@02e6e35643c009d5f88220692edfbc6b806207b1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/oliverhaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@02e6e35643c009d5f88220692edfbc6b806207b1 -
Trigger Event:
workflow_dispatch
-
Statement type: