--- id: django-zen-queries version: "2.1.0" license: BSD license_treatment: permissive maintenance: active --- # django-zen-queries — Explicit control over query execution in Django applications. License: permissive · Maintenance: active · Downloads: 155.8K/mo ## 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 above — verify before relying. Prevents unintended database queries in Django views and serializers by enforcing explicit query execution zones through context managers and decorators. 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 pip install django-zen-queries uv add django-zen-queries poetry add django-zen-queries ## Installing django-zen-queries Before you install: Low friction install with a single runtime dependency on Django. Actively maintained with recent commits and steady adoption. 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}) Requires Django and Python 3.6 or later. 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_current - Install friction: low - Maintenance: active - Downloads: 155.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django query control, prevent implicit database queries, django n+1 problem detection, explicit query execution django, django performance debugging, query execution context manager, django lazy evaluation control, django-performance, query-debugging, orm-control [View on SkillFed](https://skillfed.io/packages/django-zen-queries) · [View on PyPI](https://pypi.org/project/django-zen-queries/)