Component for Dash based on react-awesome-query-builder
Project description
Dash Query Builder
Component for Dash based on react-awesome-query-builder. The component is a way to graphically generate WHERE clauses for SQL queries.
Install
pip install dash_query_builder
Usage
To use Dash Query Builder (DQB), you need to have a Dash app and a dictionary of fields. The fields property is a dictionary of fields and their properties, following the config.fields docs. The only caveat is that JavaScript cannot be used as in the example.
For instance the following dictionary is valid:
fields = {
"qty": {
"label": "Qty",
"type": "number",
"fieldSettings": {"min": 0},
"valueSources": ["value"],
"preferWidgets": ["number"],
},
"price": {
"label": "Price",
"type": "number",
"valueSources": ["value"],
"fieldSettings": {"min": 10, "max": 100},
"preferWidgets": ["slider", "rangeslider"],
"operators": ["equal", "between"],
},
"color": {
"label": "Color",
"type": "select",
"valueSources": ["value"],
"fieldSettings": {
"listValues": [
{"value": "yellow", "title": "Yellow"},
{"value": "green", "title": "Green"},
{"value": "orange", "title": "Orange"},
]
},
},
"is_promotion": {
"label": "Promo?",
"type": "boolean",
"operators": ["equal", "is_empty"],
"valueSources": ["value"],
},
}
The basic component can be created via:
from dash import Dash, html
import dash_query_builder as dqb
fields =...
app=Dash(__name__)
app.layout=html.Div([dqb.DashQueryBuilder(fields=fields)])
app.run_server()
This will run the app similar to this:
There are other properties available as well, with defaults in parentheses.
- config({}): see CONFIG.adoc for full options
- theme("basic"): one of "antd", "mui", "fluent", "bootstrap", "basic"
- loadFormat("tree"): one of "tree", "spelFormat", "jsonLogicFormat"
- alwaysShowActionButtons(True): A boolean whether to always show action buttons, e.g. "Add Rule", "Add Group", etc.
With the above parameters, a query builder will be created with an empty tree. To pre-populate the query builder, there are several ways to do so:
loadFormat=="tree": Settreeto a valid tree object.loadFormat=="spelFormat": SetspelFormatto a valid SpEL string.loadFormat=="jsonLogicFormat": SetjsonLogicFormatto a valid jsonLogic object.
Once loadFormat is set, the tree/query builder will update when the query is changed or when the corresponding property is changed.
The loadFormat can be changed via a callback, while keeping the same tree.
Here's an example using usage.py:
Where Parser
DQB has a built-in parser for SQL queries. The parser is relatively simple as far as parsers go, but it does what I need it to.
It will parse the query and return a template string and a parameter dictionary. The template string will be in pyformat style, as
specified in PEP 249.
Example
from dash_query_builder.where_parser import WhereParser
where_parser = WhereParser()
template, params = where_parser.get_template("qty > 15 and price between 10 and 20")
print(template) # (qty > %(YSaAddDFs27s)s AND price BETWEEN %(W5PRwTGpFqqF)s AND %(N2nGExcGaUSt)s)
print(params) # {'YSaAddDFs27s': 15, 'W5PRwTGpFqqF': 10, 'N2nGExcGaUSt': 20}
Currently, only pyformat is supported. PRs are welcome!
Tools Used
- uv for Python virtual environment and dependencies.
- just for common commands
- mise-en-place to manage the toolchain.
Development
Getting Started
- Create a Python environment from previous step 1 and install:
just sync - Update the requirements and dev requirements
just compile - Build
just build - Publish
just publish - See all commands with
just -l
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 dash_query_builder-1.0.1.tar.gz.
File metadata
- Download URL: dash_query_builder-1.0.1.tar.gz
- Upload date:
- Size: 852.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a0596c0c5a0557f28c314a56afd18b17d6985f12a377ce98cf210bf990afdaa
|
|
| MD5 |
b9bf605a49fb40abd4e72b20907005dd
|
|
| BLAKE2b-256 |
964fb2f17667d64a2bf36d4d9ad00edfd41edd42e0436798be8f26334fecdf94
|
Provenance
The following attestation bundles were made for dash_query_builder-1.0.1.tar.gz:
Publisher:
release.yaml on TillerBurr/dash-query-builder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dash_query_builder-1.0.1.tar.gz -
Subject digest:
6a0596c0c5a0557f28c314a56afd18b17d6985f12a377ce98cf210bf990afdaa - Sigstore transparency entry: 285301227
- Sigstore integration time:
-
Permalink:
TillerBurr/dash-query-builder@de5d4ba4dcfe330b0ec1b84bab7afa5df6ecf017 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TillerBurr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@de5d4ba4dcfe330b0ec1b84bab7afa5df6ecf017 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dash_query_builder-1.0.1-py3-none-any.whl.
File metadata
- Download URL: dash_query_builder-1.0.1-py3-none-any.whl
- Upload date:
- Size: 878.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b7a4a38acd10c7acb9231cf52e44fdfdf241ee7daa74d5cb5d81328dd930c35
|
|
| MD5 |
a169eda85289728e1f609862e8ccbb9b
|
|
| BLAKE2b-256 |
b712110a661d3e7e0087491bddf84dd6743b8609ca8fd10c4da3eb920321f901
|
Provenance
The following attestation bundles were made for dash_query_builder-1.0.1-py3-none-any.whl:
Publisher:
release.yaml on TillerBurr/dash-query-builder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dash_query_builder-1.0.1-py3-none-any.whl -
Subject digest:
3b7a4a38acd10c7acb9231cf52e44fdfdf241ee7daa74d5cb5d81328dd930c35 - Sigstore transparency entry: 285301301
- Sigstore integration time:
-
Permalink:
TillerBurr/dash-query-builder@de5d4ba4dcfe330b0ec1b84bab7afa5df6ecf017 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TillerBurr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@de5d4ba4dcfe330b0ec1b84bab7afa5df6ecf017 -
Trigger Event:
workflow_dispatch
-
Statement type: