Skip to main content

Unit test status Documentation Status PyPI - Python Version PyPi Version

Djaq - pronounced “Jack” - is an alternative to the Django QuerySet API.

What sets it apart:

  • No need to import models

  • Clearer, more natural query syntax

  • More powerful expressions

  • More consistent query syntax without resorting to idiosyncratic methods like F() expressions, annotate(), aggregate()

  • Column expressions are entirely evaluated in the database

  • Extensible: you can write your own functions

  • Pandas: Easily turn a query into Pandas Dataframe

There is also a JSON representation of queries, so you can send queries from a client. It’s an instant API to your data. No need to write backend classes and serializers.

Djaq queries are strings. A query string for our example dataset might look like this:

DQ("Book", "name as title, publisher.name as publisher").go()

This retrieves a list of book titles with book publisher. But you can formulate far more sophisticated queries; see below. You can send Djaq queries from any language, Java, Javascript, golang, etc. to a Django application and get results as JSON. In contrast to REST frameworks, like TastyPie or Django Rest Framework (DRF), you have natural access to the Django ORM from the client.

Djaq sits on top of the Django ORM. It can happily be used alongside QuerySets.

Here’s an example comparison between Djaq and Django QuerySets that gets every publisher and counts the books for each that are above and below a rating threshold.

DQ("Book", """publisher.name,
    sumif(rating < 3, 1, 0) as below_3,
    sumif(rating >= 3, 1, 0) as above_3
    """)

compared to QuerySet:

from django.db.models import Count, Q
above_3 = Count('book', filter=Q(book__rating__gt=3))
below_3 = Count('book', filter=Q(book__rating__lte=3))
Publisher.objects.annotate(below_3=below_3).annotate(above_3=above_3)

Get average, maximum, minimum price of books:

DQ("Book", "avg(price), max(price), min(price)")

compared to QuerySet:

Book.objects.aggregate(Avg('price'), Max('price'), Min('price'))

Get the difference from the average off the maximum price for each publisher:

DQ("Book", "publisher.name, max(price) - avg(price) as price_diff")

compared to QuerySet:

from django.db.models import Avg, Max
Book.objects.values("publisher__name") \
   .annotate(price_diff=Max('price') - Avg('price'))

Release files for Djaq 1.0.9

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

Source distribution (sdist)

Source distribution for Djaq 1.0.9
File Size Uploaded
Djaq-1.0.9.tar.gz 29.0 kB Details

Release files / Djaq-1.0.9.tar.gz

Download URL Djaq-1.0.9.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1955bebfb306270fc61ea0a792efdc95c9acdc18acba351999b275d1338708cd
BLAKE2b-256 checksum
How to use checksums
125d2544c44549892068416015248b4e4a61cb8d4ab9cc6d247808356ae3b412
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.10

Release history Release notifications | RSS feed

This release

1.0.9 This release

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.0

1 release file

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