--- id: datafusion-query-builder version: "0.2.0" license: MIT license_treatment: permissive maintenance: active --- # datafusion-query-builder — Programmatic, injection-safe builder for DataFusion SQL. License: permissive · Maintenance: active · Downloads: 104.4K/mo ## 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 above — 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 pip install datafusion-query-builder uv add datafusion-query-builder 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_current - Install friction: medium - Maintenance: active - Downloads: 104.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags sql query builder, datafusion query construction, injection-safe sql generation, typed sql builder, programmatic query building, sql injection prevention, datafusion python api, sql-injection-safe, query-builder, rust-python-binding [View on SkillFed](https://skillfed.io/packages/datafusion-query-builder) · [View on PyPI](https://pypi.org/project/datafusion-query-builder/)