Skip to main content

django-deep

Django library for advanced SQL expressions: subqueries (SUM, COUNT, JsonAgg, ConcatValues), JSON extraction, and dynamic filter parsing.

Features

  • DeepManager – Custom manager with subquery helpers (get_sum_sub_query, get_count_sub_query, get_json_agg_sub_query, get_concat_values_sub_query, get_method_from_sub_query) and JsonExtract for JSON fields
  • DeepParser – Parses dynamic filter expressions from string parameters (include, exclude, order, distinct) to build Django Q objects
  • Subqueries – SumSubquery, CountSubquery, JsonAggSubquery, ConcatValuesSubquery, MethodFromSubquery, ExtractValueSubquery
  • JsonExtract – Database-agnostic JSON field extraction (PostgreSQL, MySQL, SQLite, Oracle)
  • MemoryQuerySet – In-memory queryset for testing

Installation

pip install django-deep

Quick start

from django.db import models
from django.db.models import OuterRef
from django_deep import DeepManager

class Order(models.Model):
    customer = models.ForeignKey("Customer", on_delete=models.CASCADE)
    total = models.DecimalField(max_digits=10, decimal_places=2)

class Customer(models.Model):
    name = models.CharField(max_length=255)
    objects = DeepManager()
    name = models.CharField(max_length=255)
    objects = DeepManager()

# Annotate with subqueries
Customer.objects.annotate(
    order_count=Customer.objects.get_count_sub_query(
        Order.objects.filter(customer_id=OuterRef("pk"))
    ),
    order_sum=Customer.objects.get_sum_sub_query(
        Order.objects.filter(customer_id=OuterRef("pk")), sum_field="total"
    ),
)

Subqueries

from django.db.models import OuterRef
from django_deep import DeepManager

# SumSubquery
qs.annotate(total=manager.get_sum_sub_query(Order.objects.filter(...), "total"))

# CountSubquery
qs.annotate(cnt=manager.get_count_sub_query(Order.objects.filter(...)))

# JsonAggSubquery (PostgreSQL, MySQL, SQLite, Oracle)
qs.annotate(items=manager.get_json_agg_sub_query(RelatedModel.objects.filter(...)))

JsonExtract

from django_deep.functions import JsonExtract

# Extract from JSONField
Model.objects.annotate(
    value=JsonExtract("metadata", "path__to__field")
)

Dynamic filters (DeepParser)

Parse include/exclude/order from request params:

parser = DeepParser(queryset, params={"i": "field__filter:value", "o": "name"})
compiled = parser.execute(params.get("i"))
if compiled:
    qs = queryset.filter(compiled)
qs = parser.get_queryset()

Development

pip install -e ".[dev]"
pytest
ruff check .
ruff format .

License

GPL-3.0-or-later — see the LICENSE file.

Metadata

Release files for django-deep 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-deep 0.1.1
File Size Uploaded Provenance
django_deep-0.1.1.tar.gz 29.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-deep 0.1.1
File Interpreter ABI Platform
django_deep-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 62.1 kB

Release files / django_deep-0.1.1.tar.gz

Download URL django_deep-0.1.1.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f0845a9ed9c0e7f4b26cc73ed533f342f46996abcb74fe64170ec736148f6467
BLAKE2b-256 checksum
How to use checksums
42f926fc7e6dedfd012fd16d7b3190d34b047933e95c57ae23261f1c04aefa7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Release files / django_deep-0.1.1-py3-none-any.whl

Download URL django_deep-0.1.1-py3-none-any.whl
Size 32.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f6b0ef1b2e19b06111e81ba8f37049d330f5fed0c78cd50b06183fd62f76b18
BLAKE2b-256 checksum
How to use checksums
369058a0a50b3435596d2011747c4e279e70deb261a1101a15c2887729ddfa65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Security for django-deep 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_deep-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page