Skip to main content

N+1 query detection for Django

Project description

django-nplus1

N+1 query detection for Django. Beta - API may still change before 1.0.

Quick Start

pip install django-nplus1
# settings.py
INSTALLED_APPS = [..., "django_nplus1"]
# tests.py
@pytest.mark.nplus1
class TestMyView:
    def test_list_books(self, books):
        response = client.get("/books/")  # raises NPlus1Error if view has N+1

Tests marked with @pytest.mark.nplus1 will fail if the code under test triggers an N+1 query. Fix the N+1, or use nplus1_allow() in helper functions that intentionally defer prefetching to their callers.

See examples/ for a working project and the docs for full configuration.

Credits

This project builds on the work of:

  • nplusone by Joshua Carp - the original automatic N+1 detection library for Python ORMs. django-nplus1 started as a Django-specific fork of nplusone's architecture.
  • django-zeal by Tao Bojlen - inspired several features including deferred field detection, .get()-in-a-loop detection, ContextVar-based async safety, call-site tracking, and configurable thresholds.

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.0.tar.gz (14.2 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.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file django_nplus1-0.1.0.tar.gz.

File metadata

  • Download URL: django_nplus1-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_nplus1-0.1.0.tar.gz
Algorithm Hash digest
SHA256 863d1feaee7ae4fc4056638f8e7f5af09ecea27f6a75b23b73cac1449ead1da2
MD5 309de8b8addd9a00f40aaedb7931a4b8
BLAKE2b-256 adad9110ab9e6cccb25e70f6d33d442175817e44590102b057d0b3f5302dd457

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_nplus1-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: django_nplus1-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_nplus1-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 866c77f4886ca67b0d87a2292f39c34f9a6d9d2fc820f69756d5c678c7a2f3a1
MD5 5b5e728ce5de74aceda07f3490251e86
BLAKE2b-256 c88aae29880032cea5313ca276c1d759b414b6a75320d794acefd6b67d26c50a

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_nplus1-0.1.0-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