django-zen-queries
Explicit control over query execution in Django applications.
Decision gist · record as of 2026-08-14
Yes, if you develop Django applications and want to catch N+1 and other implicit query problems during development. The package is lightweight, actively maintained, and widely used. Install it in development environments to enforce explicit query boundaries; the overhead is negligible for a debugging tool. Most teams use it as a development-time safety net rather than in production.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Django and Python 3.6 or later.
- Low friction install with a single runtime dependency on Django.
- Actively maintained with recent commits and steady adoption.
License · maintenance · safety
BSD (permissive) — BSD license is permissive and poses no restrictions on commercial or private use.
last release 2021-07-27 (1844 days) · last repo commit 2026-08-04 · 388 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 155,817 downloads/mo, #10,799 on PyPI
Alternatives
Verify before relying
pip install django-zen-queries
from django_zen_queries import queries_disabled, fetch
def menu(request):
pizzas = fetch(Pizza.objects.all())
with queries_disabled():
return render(request, 'menu.html', {'pizzas': pizzas})- Whether the package works with Django versions released after 3.1 (last tested version in description).
- Performance overhead of the query-blocking mechanism in production environments.
- Current compatibility with modern Django and Python versions beyond those mentioned in the description.
What it is and what it does
django-zen-queries is a Django debugging and design tool that makes database query execution explicit rather than implicit. It provides context managers and decorators that prevent code from running queries unless explicitly allowed, forcing developers to think about when and where data is fetched versus rendered. The package addresses a fundamental Django ORM weakness: lazy evaluation hides query execution, making it easy to accidentally trigger the N+1 problem when templates or serializers access related data without proper prefetching.
The package includes a queries_disabled context manager and decorator, a fetch utility to force queryset evaluation, and integration helpers for Django templates and Django REST Framework serializers. It does not optimize queries itself—instead, it fails loudly when queries run where they shouldn't, pushing developers to design code that separates data fetching from data rendering.
Use it for
- Wrap template rendering in views to catch N+1 query problems before production.
- Decorate serializer methods to prevent REST Framework endpoints from unexpectedly querying during serialization.
- Enforce architectural boundaries where certain functions should never trigger database access.
- Debug performance regressions by identifying which code paths execute unexpected queries.
- Use as a development-time safety net to catch query problems introduced by template or serializer changes.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you develop Django applications and want to catch N+1 and other implicit query problems during development.
The package is lightweight, actively maintained, and widely used. Install it in development environments to enforce explicit query boundaries; the overhead is negligible for a debugging tool. Most teams use it as a development-time safety net rather than in production.
Install
django-zen-queries on PyPI
Before you install
Low friction install with a single runtime dependency on Django. Actively maintained with recent commits and steady adoption.
Requires Django and Python 3.6 or later.
License in practice
BSD license is permissive and poses no restrictions on commercial or private use.
Quickstart
pip install django-zen-queries
from django_zen_queries import queries_disabled, fetch
def menu(request):
pizzas = fetch(Pizza.objects.all())
with queries_disabled():
return render(request, 'menu.html', {'pizzas': pizzas})
Verify before relying
- Whether the package works with Django versions released after 3.1 (last tested version in description).
- Performance overhead of the query-blocking mechanism in production environments.
- Current compatibility with modern Django and Python versions beyond those mentioned in the description.
Package facts
| License | BSD permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packageDjango |
| Maintenance | Actively maintained 1,844 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 155,817 / month, #10,799 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
Evidence: django_zen_queries-2.1.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “django query control”
- django-zen-queriesPrevents unintended database queries in Django views and serializers…
- django-pgactivityProvides Django management commands and utilities to view, filter,…
- drf-flex-fieldsAdds dynamic field expansion and sparse field selection to Django…
Give your agent the search over MCP, or paste the wish link into any chat.
More Quality Assurance packages
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
Ruff is a Python linter and code formatter written in Rust that combines linting, formatting, and code fixing into a single tool, replacing Flake8, Black, isort, and related utilities.
Pexpect spawns and controls interactive console applications by sending input and matching output patterns, automating tasks that would otherwise require manual interaction.
Black reformats Python source code to a consistent style by parsing entire files and rewriting them according to an opinionated, deterministic set of rules, eliminating manual formatting decisions.
pytest-xdist distributes pytest tests across multiple CPU cores or machines to speed up test execution, with the simplest usage being `pytest -n auto` to spawn workers equal to available CPUs.
Install it if your test suite takes long enough that parallelization would save meaningful time.
Validates AWS CloudFormation templates in YAML or JSON format against resource provider schemas and best practices, checking property values and configuration correctness.
Install it if you work with CloudFormation templates.
See also django-pgactivity · drf-access-policy · djangorestframework-role-filters · drf-dynamic-fields · django-mock-queries · django-query-builder · django-ordered-model · adrf · django-pg-returning · django-read-only