Skip to main content

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_related or prefetch_related results are never accessed
  • Middleware: Automatically monitors all requests
  • pytest plugin: nplus1 fixture and @pytest.mark.nplus1 marker 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


Download files

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

Source Distribution

django_nplus1-0.1.0a1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_nplus1-0.1.0a1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

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

Hashes for django_nplus1-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 9da6b2526d71e20c5feaad46f0fceb77ede2ec3f64c7ce8a3418fbc92ef247a0
MD5 091fdf40605c8b3583fee9bd602d30be
BLAKE2b-256 0a5cb08dd4d60dcc680042a5abd74a2f593af32e486e02a70a5d4ebfb2631b6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_nplus1-0.1.0a1.tar.gz:

Publisher: publish.yml on oliverhaas/django-nplus1

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_nplus1-0.1.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_nplus1-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 8790088b31a633779b8800f95fbf7066fa0a7c2b5cfa939ae9267b76dca9a6bc
MD5 2d159b0e7b49878fde46bafc5e0c06a8
BLAKE2b-256 ee11cb5e94373ff81538415c292066785c3ab9996330c5dd6412df7d21bf5c36

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_nplus1-0.1.0a1-py3-none-any.whl:

Publisher: publish.yml on oliverhaas/django-nplus1

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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