--- id: django-sql-utils version: "0.7.0" license: unclear license_treatment: permissive maintenance: dormant --- # django-sql-utils — Improved API for aggregating using Subquery License: permissive · Maintenance: dormant · Downloads: 183.9K/mo ## What it is and what it does django-sql-utils wraps Django's queryset annotation API to generate more efficient SQL for common aggregation patterns. Instead of using Django's default JOIN-based aggregations, it provides subquery-based alternatives like SubqueryCount, SubqueryMin, SubqueryMax, SubquerySum, and SubqueryAvg that often perform better on large datasets. It also simplifies the syntax for annotating querysets with existence checks via a streamlined Exists API. The package targets developers working with Django who need to optimize query performance or find Django's native aggregation syntax verbose. It depends on django and sqlparse as runtime dependencies and requires Python >= 3.8. The codebase has been dormant since 2023-09-28, so compatibility with the latest Django releases is not guaranteed without verification. Use it for: - Annotate a Parent queryset with a count of related Child objects using a subquery instead of a JOIN for better performance. - Add a boolean annotation to check whether a parent has any children, using a simpler API than Django's native Exists. - Use SubqueryAggregate with PostgreSQL aggregates to collect related field values without writing complex subquery syntax. - Replace verbose Django subquery and OuterRef patterns with cleaner, more maintainable annotation calls. - Optimize queries that would otherwise use GROUP BY and JOIN, which can be slower than subquery-based aggregation. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides simplified APIs for Django querysets to generate optimized SQL, particularly for subquery-based aggregations and existence checks that are more performant than Django's default JOIN-based approaches. Yes, if you are actively using Django and need to optimize aggregation queries. The package solves a real performance problem and has a clean API. However, verify compatibility with your Django version first—the package has been dormant since 2023-09-28 and may not work with very recent Django releases. No known security vulnerabilities. ## Install pip install django-sql-utils uv add django-sql-utils poetry add django-sql-utils ## Installing django-sql-utils Before you install: Low friction: pure Python wheel with only django and sqlparse as runtime dependencies. Dormant since last commit on 2023-09-28; repository is not archived and has 143 stars, but no recent maintenance activity. License in practice: MIT license (permissive); you can use, modify, and distribute this package freely with minimal restrictions. Quickstart: pip install django-sql-utils from django_sql_utils import SubqueryCount Parent.objects.annotate(child_count=SubqueryCount('child')) Requires Django and Python >= 3.8; the package is dormant and may not be compatible with very recent Django versions. Verify before relying: - Compatibility with Django versions released after 2023-09-28 is unclear given the dormant maintenance status. - Whether sqlparse is used directly by the package or only as a transitive dependency of django. - The exact module path for importing SubqueryCount and other utilities from the package. ## Package facts - License: not declared (permissive) - Python support: supports_current - Install friction: low - Maintenance: dormant - Downloads: 183.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django subquery aggregation, django queryset optimization, django sql generation, django count subquery, django exists annotation, django query performance, django aggregate subquery, django-orm, query-optimization, sql-generation [View on SkillFed](https://skillfed.io/packages/django-sql-utils) · [View on PyPI](https://pypi.org/project/django-sql-utils/)