django-sql-utils
Improved API for aggregating using Subquery
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Django and Python >= 3.8; the package is dormant and may not be compatible with very recent Django versions.
- 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 · maintenance · safety
permissive license (permissive) — MIT license (permissive); you can use, modify, and distribute this package freely with minimal restrictions.
last release 2023-09-28 (1051 days) · last repo commit 2023-09-28 · 143 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 183,905 downloads/mo, #10,053 on PyPI
Alternatives
Verify before relying
pip install django-sql-utils
from django_sql_utils import SubqueryCount
Parent.objects.annotate(child_count=SubqueryCount('child'))- 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.
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 on this page. Verify before relying on it.
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
django-sql-utils on PyPI
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.
Requires Django and Python >= 3.8; the package is dormant and may not be compatible with very recent Django versions.
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'))
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 | permissive license permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesdjangosqlparse |
| Maintenance | Dormant 1,051 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 183,905 / month, #10,053 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 |
Evidence: django_sql_utils-0.7.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 subquery aggregation”
- django-sql-utilsProvides simplified APIs for Django querysets to generate optimized…
- django-snowflakeProvides a Django database backend that connects Django ORM to…
- python-logstashSends Python log records to Logstash over UDP or TCP, formatting them…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also django-tree-queries · django-cacheops · django-query-builder · django-mock-queries · django-chunkator · django-cte · django-pg-returning · gw-dsl-parser · django-pg-bulk-update · django-mysql