Django Enhanced Expression Parser
Project description
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) andJsonExtractfor 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_deep-0.1.1.tar.gz.
File metadata
- Download URL: django_deep-0.1.1.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0845a9ed9c0e7f4b26cc73ed533f342f46996abcb74fe64170ec736148f6467
|
|
| MD5 |
985cb7b0bb7bf4793294578e9136a949
|
|
| BLAKE2b-256 |
42f926fc7e6dedfd012fd16d7b3190d34b047933e95c57ae23261f1c04aefa7c
|
Provenance
The following attestation bundles were made for django_deep-0.1.1.tar.gz:
Publisher:
release.yml on octolo/django-deep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_deep-0.1.1.tar.gz -
Subject digest:
f0845a9ed9c0e7f4b26cc73ed533f342f46996abcb74fe64170ec736148f6467 - Sigstore transparency entry: 1702220276
- Sigstore integration time:
-
Permalink:
octolo/django-deep@a636a0d70d1d2176bf71f64ce662e2d97f2819f6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/octolo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a636a0d70d1d2176bf71f64ce662e2d97f2819f6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_deep-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_deep-0.1.1-py3-none-any.whl
- Upload date:
- Size: 32.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f6b0ef1b2e19b06111e81ba8f37049d330f5fed0c78cd50b06183fd62f76b18
|
|
| MD5 |
a6922f722bfe6171a288bea815aabfb8
|
|
| BLAKE2b-256 |
369058a0a50b3435596d2011747c4e279e70deb261a1101a15c2887729ddfa65
|
Provenance
The following attestation bundles were made for django_deep-0.1.1-py3-none-any.whl:
Publisher:
release.yml on octolo/django-deep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_deep-0.1.1-py3-none-any.whl -
Subject digest:
8f6b0ef1b2e19b06111e81ba8f37049d330f5fed0c78cd50b06183fd62f76b18 - Sigstore transparency entry: 1702220361
- Sigstore integration time:
-
Permalink:
octolo/django-deep@a636a0d70d1d2176bf71f64ce662e2d97f2819f6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/octolo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a636a0d70d1d2176bf71f64ce662e2d97f2819f6 -
Trigger Event:
push
-
Statement type: