nplusone
Detecting the n+1 queries problem in Python
What it is and what it does
nplusone is an ORM profiling tool that detects the n+1 queries problem—a common performance pitfall where an application issues many redundant database queries instead of using efficient joins or batch loading. It integrates with Django, Flask-SQLAlchemy, Peewee, and generic WSGI applications to monitor query patterns during development.
The tool logs warnings when it detects lazy-loaded relationships that could be eagerly loaded for better performance, and also warns about eagerly loaded data that is never accessed in the current request. It supports both framework middleware integration (Django, Flask) and a generic profiler context manager for non-HTTP code. Configuration options allow raising exceptions on detected problems to fail automated tests, and whitelisting specific models or fields to suppress false positives.
Use it for:
- Identify n+1 query patterns during Django development before they reach production
- Profile Flask-SQLAlchemy applications to find inefficient relationship loading
- Detect unused eager loads that waste database resources in request handlers
- Enforce query efficiency in automated tests by raising exceptions on n+1 detection
- Diagnose slow ORM performance by pinpointing the exact code lines causing lazy loads
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Detects n+1 query problems in Python ORMs (Django, SQLAlchemy, Peewee) by monitoring lazy and eager loading patterns and logging warnings when inefficient queries are emitted.
No—not for new projects. The package is abandoned (last release May 2018, no commits since November 2022) and its license treatment is unclear. While it solves a real problem and has low install friction, modern Django and SQLAlchemy versions may not be fully supported, and there is no active maintenance. Consider modern alternatives like django-silk, django-debug-toolbar, or SQLAlchemy's own query analysis tools for current development.
Install
nplusone on PyPI
pip
pip install nplusoneuv
uv add nplusonepoetry
poetry add nplusoneInstalling nplusone
Before you install
Low install friction with only two runtime dependencies (six and blinker). However, the project is abandoned—last release was in May 2018 and no commits since November 2022. Not suitable for production use; development-only tool.
License in practice
License treatment is unclear; raw license text indicates copyright by Joshua Carp but no SPDX identifier is present. Verify licensing terms before use in proprietary or commercial contexts.
Quickstart
pip install nplusone
# Django: add to INSTALLED_APPS and MIDDLEWARE
INSTALLED_APPS = (..., 'nplusone.ext.django')
MIDDLEWARE = ('nplusone.ext.django.NPlusOneMiddleware', ...)
# Flask-SQLAlchemy
from nplusone.ext.flask_sqlalchemy import NPlusOne
app = Flask(__name__)
NPlusOne(app)
Development-only tool; do not deploy to production. Requires Django >= 1.8 or Flask-SQLAlchemy for framework integrations.
Verify before relying
- Whether the unclear license permits commercial or proprietary use
- Compatibility with modern Django and SQLAlchemy versions released after 2018
- Whether the tool functions correctly with current ORM lazy/eager loading patterns
Package facts
| License | Copyright 2016 Joshua Carp (unclear) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — six, blinker |
| Maintenance | abandoned — 3,007 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 600,458/month — #5,821 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: nplusone-1.0.0-py2.py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
django-zealDetects N+1 query problems in Django…
unclear · top 15,000 on PyPI
sqlalchemy-mixinsProvides Active Record-style mixins for…
permissive · top 15,000 on PyPI
pylint-flask-sqlalchemyA Pylint plugin that suppresses false-positive…
copyleft · top 15,000 on PyPI
sqltapsqltap hooks into SQLAlchemy to collect and…
permissive · top 15,000 on PyPI
peeweePeewee is a lightweight ORM that maps Python…
unclear · top 1,000 on PyPI
SQLAlchemySQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
Flask-SQLAlchemyFlask-SQLAlchemy integrates SQLAlchemy database…
permissive · top 1,000 on PyPI
sqlalchemy-filtersAdds filtering, sorting, and pagination…
permissive · top 15,000 on PyPI
django-pg-returningExtends Django's ORM to capture and return rows…
permissive · top 15,000 on PyPI
ormarAn async ORM for Python that unifies database…
permissive · top 15,000 on PyPI