![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Component for Dash based on react-awesome-query-builder. The component is a way to graphically generate WHERE clauses for SQL queries.
pip install dash_query_builder
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.
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"
: Set tree
to a valid tree object.loadFormat=="spelFormat"
: Set spelFormat
to a valid SpEL string.loadFormat=="jsonLogicFormat"
: Set jsonLogicFormat
to 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
:
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.
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!
just sync
just compile
just build
just publish
just -l
FAQs
Component for Dash based on react-awesome-query-builder
We found that dash-query-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.