skillfed

datafusion-query-builder

Programmatic, injection-safe builder for DataFusion SQL.

datafusion-query-builder v0.2.0 104.4K downloads/30d#12,749 on PyPI
Permissive license MIT Active released

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-builder

uv

uv add datafusion-query-builder

poetry

poetry add datafusion-query-builder

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3 :: OnlyProgramming Language :: RustTopic :: DatabaseTyping :: Typed

Tags

sql query builderdatafusion query constructioninjection-safe sql generationtyped sql builderprogrammatic query buildingsql injection preventiondatafusion python api
sql-injection-safequery-builderrust-python-binding

More Database packages