django-query-tools
Tools for building queries in Django.
Setup
$ pip install django-query-tools
To use the server module, Django must also be installed:
$ pip install django
Usage
# script.py
from django_query_tools.client import F
from django_query_tools.server import make_atoms, make_query
from django.db.models import Q
# --- CLIENT ---
# Define x and y fields
x = F(x="hello")
print("F object for x:", x)
print("Data:", x.query)
y = F(y="goodbye")
print("F object for y:", y)
print("Data:", y.query)
# Form a query from x and y
query = x & ~y
print("Query F object:", query)
print("Client sends data:", query.query)
# --- SERVER ---
# Server receives query
data = query.query
print("Server receives data:", data)
# Modifies data in-place, creating QueryAtom keyvalue pairs
# Returns these QueryAtom objects for validation
atoms = make_atoms(data)
print("QueryAtom structure:", data)
print("QueryAtom objects:", atoms)
# Builds Django Q object from the QueryAtom objects
formed = make_query(data)
expected = Q(x="hello") & ~Q(y="goodbye")
print("Formed Q object:", formed)
print("Expected Q object:", expected)
print("These objects represent the same query:", formed == expected)
$ python script.py
F object for x: <django_query_tools.client.F object at 0x1012f1910>
Data: {'x': 'hello'}
F object for y: <django_query_tools.client.F object at 0x1012f1990>
Data: {'y': 'goodbye'}
Query F object: <django_query_tools.client.F object at 0x1012f3510>
Client sends data: {'&': [{'x': 'hello'}, {'~': {'y': 'goodbye'}}]}
Server receives data: {'&': [{'x': 'hello'}, {'~': {'y': 'goodbye'}}]}
QueryAtom structure: {'&': [{'x': <django_query_tools.server.QueryAtom object at 0x1012f1a10>}, {'~': {'y': <django_query_tools.server.QueryAtom object at 0x1023b1890>}}]}
QueryAtom objects: [<django_query_tools.server.QueryAtom object at 0x1012f1a10>, <django_query_tools.server.QueryAtom object at 0x1023b1890>]
Formed Q object: (AND: ('x', 'hello'), (NOT (AND: ('y', 'goodbye'))))
Expected Q object: (AND: ('x', 'hello'), (NOT (AND: ('y', 'goodbye'))))
These objects represent the same query: True
Metadata
Release files for django-query-tools 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_query_tools-0.3.3.tar.gz | 5.4 kB | Without provenance | Details for django_query_tools-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_query_tools-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for django_query_tools-0.3.3-py3-none-any.whl |
Total release size: 11.8 kB
Release files / django_query_tools-0.3.3.tar.gz
| Download URL | django_query_tools-0.3.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54f3019320cf6f61284318103cd356b444df7e33eb567d55e59103c3516e5361
|
|
BLAKE2b-256 checksum How to use checksums |
33fe568613afa53ea76eb8fede4bab89783870df1112eb724b2da16bf797849a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / django_query_tools-0.3.3-py3-none-any.whl
| Download URL | django_query_tools-0.3.3-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9da1995c5d75c7895e58ce3cf7aabe6249fa4dd22cfa6d096f0c70c62c274570
|
|
BLAKE2b-256 checksum How to use checksums |
10d50f55603d7e9baa9d5cfe4912d2959bc74399a03be81d92e30eddb03cc465
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for django-query-tools 0.3.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.