datafusion-query-builder
Programmatic, injection-safe builder for DataFusion SQL.
What it is and what it does
datafusion-query-builder is a typed SQL query builder for DataFusion, written in Rust with a Python API exposed via PyO3. It replaces hand-rolled SQL strings with a composable, type-safe interface that automatically escapes values by construction—untrusted input like column values or user-supplied filters are safe to embed without manual quoting. The builder emits actual SQL text (not an AST or opaque object), so queries remain visible in logs, greppable, and cache-keyable.
The library provides a façade layer over sqlparser, handling expressions, filters, selections, grouping, and ordering through method chaining. Python scalars auto-promote to literals; specialized operators like JSONB key-exists checks (`has_key`, `has_any_key`, `has_all_keys`) are first-class. An explicit `raw()` escape hatch and `param()` placeholders allow stepping outside the standard grammar when needed. The crate is correctness-critical and tested against DataFusion itself as an oracle to catch silent encoding errors.
Use it for:
- Build dynamic SQL filters from user input without manual escaping or string concatenation.
- Generate analytics queries programmatically while keeping SQL visible in application logs.
- Construct complex DataFusion queries with type safety and composable method chaining.
- Embed untrusted column names or filter values safely without SQL injection risk.
- Test query generation logic with deterministic, re-parseable SQL output.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Builds DataFusion SQL queries programmatically with injection-safe value handling, emitting readable SQL text rather than requiring string concatenation or templates.
Yes, if you build DataFusion queries from user input or dynamic parameters. The injection-safe-by-construction design and readable SQL output make it worth the medium install friction. Alpha status and 26-day-old release suggest active development; verify dialect coverage for your specific query patterns before production use.
Install
datafusion-query-builder on PyPI
pip
pip install datafusion-query-builderuv
uv add datafusion-query-builderpoetry
poetry add datafusion-query-builderInstalling datafusion-query-builder
Before you install
Medium install friction due to compiled Rust wheels; prebuilt abi3 wheels available for CPython 3.9+ on macOS (both architectures) and Linux (x86_64 and aarch64). Active maintenance with a release 26 days ago.
License in practice
MIT license permits commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
from datafusion_query_builder import col, table, functions as f
q = table("records").filter(col("kind") == "span").select(
f.coalesce(col("service_name"), "(unknown)").alias("service")
).limit(200)
print(q.to_sql())
Requires Python 3.9 or later; prebuilt wheels available for common platforms (macOS arm64/x86_64, Linux x86_64/aarch64).
Verify before relying
- Whether the library's DataFusion SQL dialect coverage matches your specific query patterns.
- Performance characteristics when building very large or deeply nested queries.
- Stability guarantees given the Alpha development status.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 26 days since the last release |
| First released | |
| Downloads | 104,416/month — #12,749 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: datafusion_query_builder-0.2.0-cp39-abi3-macosx_11_0_arm64.whl; datafusion_query_builder-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; datafusion_query_builder-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Keywords: datafusion, sql, query-builder, sqlparser
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
datafusionDataFusion is a Python binding to Apache…
permissive · top 5,000 on PyPI
sqlfluffrsSQLFluff-rs is a Rust-based optional component…
permissive · top 15,000 on PyPI
buildpgbuildpg constructs PostgreSQL prepared…
permissive · top 15,000 on PyPI
django-query-builderBuilds and executes complex SQL queries…
permissive · top 15,000 on PyPI
ibis-frameworkIbis is a portable Python dataframe library…
permissive · top 5,000 on PyPI
SQLAlchemySQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
syntaqliteParse, format, validate, and tokenize SQLite…
permissive · top 15,000 on PyPI
apache-airflow-providers-common-sqlProvides common SQL operators, hooks, and…
permissive · top 1,000 on PyPI
sqloxidesqloxide parses SQL queries into a typed…
permissive · top 15,000 on PyPI
PyPikaPyPika is a Python API for building SQL queries…
permissive · top 5,000 on PyPI