Skip to main content

KQLBridge

KQL → Spark SQL / T-SQL transpiler for Microsoft Fabric and Databricks

PyPI version Eval Score License Python

KQLBridge lets data engineers write queries in Kusto Query Language (KQL) and compile them to Spark SQL (Databricks, Microsoft Fabric Spark notebooks) or T-SQL (Fabric SQL Warehouse, Synapse Analytics).

from kqlbridge import translate

kql = "AppLogs | where Level == 'Error' | summarize count() by ServiceName"
sql = translate(kql, target="spark")
# → SELECT ServiceName, COUNT(*) FROM AppLogs WHERE Level = 'Error' GROUP BY ServiceName

Why KQLBridge?

Microsoft Fabric runs two query engines side by side: Eventhouse (KQL) and Spark notebooks / SQL Warehouse (Spark SQL / T-SQL). Teams that wrote years of KQL analytics can't simply copy-paste those queries into a Spark cell. KQLBridge automates the translation.

Use cases:

  • Migrate ADX / Eventhouse KQL workloads to Databricks or Fabric Spark
  • Build routing agents that pick the right engine per query at runtime
  • Teach polyglot data engineering — learn one language, compile to all targets

Installation

pip install kqlbridge

Requires: Python 3.10+, no external services, no API keys.


Quick Start

Python API

from kqlbridge import translate, detect_operators, is_supported

# Translate KQL → Spark SQL (Microsoft Fabric Lakehouse / Databricks)
sql = translate(
    "AppLogs | where TimeGenerated > ago(24h) | project Message, Level",
    target="spark"
)

# Translate KQL → T-SQL (Microsoft Fabric SQL Warehouse / Synapse)
sql = translate(
    "AppLogs | where TimeGenerated > ago(24h) | project Message, Level",
    target="tsql"
)

# Check which operators are used
ops = detect_operators("AppLogs | where Level == 'Error' | summarize count() by Host")
# → ['where', 'summarize']

# Gate unsupported queries before translating
if is_supported(kql):
    sql = translate(kql)
else:
    print("Unsupported operators — keep in KQL engine")

CLI

# Translate to Spark SQL (default)
kqlbridge translate "AppLogs | where Level == 'Error' | summarize count() by Host"

# Translate to T-SQL
kqlbridge translate "Events | where ts > ago(7d) | take 100" --tsql

# Check if a query is supported (exit 0 = yes, exit 1 = no — useful in CI)
kqlbridge check "AppLogs | where Level == 'Error' | join (Users) on UserId"

# List all supported operators
kqlbridge operators

Supported Operators (v0.2)

KQL Operator Spark SQL Output Status
where WHERE clause ✅ v0.1
project SELECT columns ✅ v0.1
summarize count() SELECT COUNT(*) GROUP BY ✅ v0.1
summarize sum/avg/min/max Aggregation functions ✅ v0.1
bin(col, 1h) DATE_TRUNC('hour', col) ✅ v0.1
ago(1h) CURRENT_TIMESTAMP - INTERVAL '1 hours' ✅ v0.1
extend SELECT *, expr AS alias ✅ v0.1
order by / sort by ORDER BY col ASC/DESC ✅ v0.1
take / limit LIMIT n ✅ v0.1
distinct SELECT DISTINCT ✅ v0.1
join (inner) INNER JOIN ON key ✅ v0.1
union UNION ALL ✅ v0.1
let variables CTEs (WITH … AS) ✅ v0.1
count() COUNT(*) scalar ✅ v0.1

See supported_operators.md for full reference. See unsupported_operators.md for operators with no SQL equivalent.


Debugging & Jules Integration

KQLBridge includes a robust diagnostic framework optimized for developers and autonomous testing agents (like Jules). Failed tests from the stress suite (run_stress_test.py) are automatically serialized as detailed markdown reports inside .jules/.

See the complete Debugging and Jules Integration Guide to learn how to:

  • Trace Lark AST trees and token parses.
  • Integrate step-by-step VS Code debugging.
  • Retrieve local diagnostic logs for auto-remediation.

Eval Score

KQLBridge measures accuracy against a locked 100-query benchmark (70 standard, 20 edge-case, 10 adversarial). The eval script is the single source of truth — it is never modified by the agent loop.

python tests/eval/prepare.py
# SCORE: 100.0% (120/120)

Architecture

KQL input
  → Lark lexer (LOCKED grammar: kql.lark)
  → Parser (MODIFIABLE: parser.py)
  → AST nodes (LOCKED: ast_nodes.py)
  → Semantic check (LOCKED: semantic.py)
  → Generator (MODIFIABLE: generators/spark_sql.py)
  → Spark SQL / T-SQL output

Locked files (oracle, grammar, types) are never touched by the agentic build loop. Modifiable files (parser, generators) are where improvements happen.


Contributing

All contributions must include a corresponding test case in tests/eval/benchmark.json. PRs that do not include a new test case will not be merged.

git clone https://github.com/navakanth/kqlbridge
cd kqlbridge
pip install -e ".[dev]"
python tests/eval/prepare.py  # baseline score
pytest tests/                 # unit tests

See CONTRIBUTING.md for full guidelines.


Companion Projects

  • PipeQL — Pipe-first SQL syntax that compiles to the same Spark SQL target (v0.2 roadmap)
  • DE-Context Kit — Routing agent + CDLC skill packages using KQLBridge under the hood

License

Apache 2.0. See LICENSE.

Metadata

Release files for kqlbridge 0.12.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kqlbridge 0.12.1
File Size Uploaded Provenance Actions
kqlbridge-0.12.1.tar.gz 153.6 kB Without provenance Details for kqlbridge-0.12.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kqlbridge 0.12.1
File Interpreter ABI Platform Actions
kqlbridge-0.12.1-py3-none-any.whl Python 3 none any Details for kqlbridge-0.12.1-py3-none-any.whl

Total release size: 260.2 kB

Release files / kqlbridge-0.12.1.tar.gz

Download URL kqlbridge-0.12.1.tar.gz
Size 153.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2828e47cb268188cb04d319a24f766982e45dc246e6a951ddc8ec8044ad11252
BLAKE2b-256 checksum
How to use checksums
13ee2ebd9fbcd5d2ce850ab361b928e5426838b7d79e152463df1f96f79f537e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / kqlbridge-0.12.1-py3-none-any.whl

Download URL kqlbridge-0.12.1-py3-none-any.whl
Size 106.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6380ce21ec61908f10773c735a0e68ddfeea8f3b9d8388e1bb97417b4d3e7244
BLAKE2b-256 checksum
How to use checksums
d391ba3aacb7b976692f65d8d0817eb1166fb5ab54c5d92940836931124c7e70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for kqlbridge 0.12.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page