Metadata-Version: 2.4
Name: sqlbabel-cli
Version: 0.28.0
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES
Summary: The native sqlbabel executable: evidence-backed translation of Snowflake and Databricks SQL into DuckDB SQL.
Home-Page: https://github.com/sqlstack-io/sqlbabel
License-Expression: Apache-2.0 AND MIT
Requires-Python: >=3.12
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sqlstack-io/sqlbabel/main/.github/sqlbabel-logo-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/sqlstack-io/sqlbabel/main/.github/sqlbabel-logo-light.png">
    <img src="https://raw.githubusercontent.com/sqlstack-io/sqlbabel/main/.github/sqlbabel-logo-light.png" alt="SQLBabel" width="420">
  </picture>
  <br>
  <sub>by <a href="https://sqlstack.io">SQLStack</a></sub>
</p>

<h3 align="center">Evidence-backed SQL translation.</h3>

<p align="center">
  Translate Snowflake and Databricks SQL into DuckDB SQL. Every rule is proven against real warehouse results. When SQLBabel won't translate, it tells you exactly why.
  <br>
  <a href="https://sqlbabel.io/">Website</a> ·
  <a href="https://sqlbabel.io/docs/">Docs</a> ·
  <a href="https://sqlbabel.io/playground/">Playground</a> ·
  <a href="https://sqlbabel.io/docs/quickstart/">Quickstart</a>
</p>

<p align="center">
  <img src="https://raw.githubusercontent.com/sqlstack-io/sqlbabel/main/.github/demos/check-convert.gif" alt="SQLBabel checks SQL and converts queries to DuckDB SQL">
</p>

## Why SQLBabel?

SQL that runs on two engines doesn't always return the same answer. NULLs, decimal arithmetic and casts can behave differently.

SQLBabel checks its conversion rules against real results from the source warehouse. It handles those differences deliberately and gives you precise diagnostics when it can't convert a query - not plausible-looking SQL and crossed fingers.

SQLBabel's parser started as a fork of [Polyglot](https://github.com/tobilg/polyglot), a Rust SQL transpiler inspired by [SQLGlot](https://github.com/tobymao/sqlglot). The translation to DuckDB, the typing and the recorded evidence behind them are SQLBabel's own.

- **Proven rules.** Every conversion rule is checked against real results recorded on the warehouse.
- **A precise no.** When a query won't translate, you get a code, the exact span and the reason.
- **Check early.** Catch invalid SQL before it reaches the warehouse.
- **See what's blocking you.** Scan a SQL project to find what converts and what needs attention.
- **Choose what to accept.** Allow or refuse each known difference in `sqlbabel.toml`.
- **Test locally.** Run converted queries on DuckDB against small fixtures, in tests and CI.

## Get started

```bash
pip install sqlbabel

# Convert your first query
echo "SELECT 1 AS total" | sqlbabel convert --no-config

# Check a SQL file
sqlbabel check query.sql

# Convert a query using the tables in sources/*.yml
sqlbabel convert query.sql
```

Or **[try the playground](https://sqlbabel.io/playground/)** - no installation needed.

See the [supported dialects and coverage](https://sqlbabel.io/docs/coverage/), [project guide](https://sqlbabel.io/docs/project/) and [defaults for known differences](https://sqlbabel.io/docs/policy/) for the details.

## Use it from Python

```python
import sqlbabel

result = sqlbabel.convert(
    sql="SELECT 1 AS total",
    options=sqlbabel.ConvertOptions(no_config=True),
)
```

[Python API](https://sqlbabel.io/docs/python/)

## Running the suites

SQLBabel's parsers and conversion rules are checked against evidence recorded on the real engines. Rerunning it needs no account:

```bash
git clone https://github.com/sqlstack-io/sqlbabel && cd sqlbabel
uv sync
make check-syntax DIALECT=snowflake    # rerun the parser against recorded syntax evidence
make check-convert DIALECT=snowflake   # replay recorded translations on DuckDB
```

| Command | What it does |
|---|---|
| `make pending DIALECT=snowflake` | What isn't recorded yet, in both suites |
| `make check-syntax DIALECT=snowflake` | Rerun the parser against recorded evidence (offline) |
| `make record-syntax DIALECT=duckdb` | Record evidence for new syntax cases |
| `make check-convert DIALECT=snowflake [CASES=temporal]` | Replay recorded translations on DuckDB (offline) |
| `make record-convert DIALECT=snowflake` | Record new translation cases on Snowflake |
| `make verify-changed` | Replay only the cases whose conversion or recording changed since its last run |
| `make check-merge` | The static checks and the Rust tests every change must pass |
| `make test-crate CRATE=sqlbabel-evidence` | One crate's tests |
| `make python-api` | Build the Python module and run its API tests |

A pull request runs what its changed files need. Documentation and website changes build and check the site. Other changes run `make check-merge`, the Python tests and the replay. The replay reuses main's judgement for every case whose conversion and recording are unchanged, and replays only the rest. A change under one of the full-replay paths in `scripts/replay_scope/constants.py` replays every case: the DuckDB pin, the lock files, the replay, comparison and policy crates, the error kinds, CI's toolchain and the evidence pin. A change outside every crate the `sqlbabel` binary is built from replays nothing.

Recording needs the dialect's engine: DuckDB and SQLite record locally, while Snowflake, BigQuery and Databricks need a connection. Recording Snowflake syntax evidence isn't public yet. `make help` lists every target.

## Credits

SQLBabel wouldn't exist without two projects:

- **[Polyglot](https://github.com/tobilg/polyglot)** by Tobias ([@tobilg](https://github.com/tobilg)). SQLBabel's tokenizer, parser and syntax tree are a modified fork of Polyglot's, and much of that code is still his. Tobias also fixed many issues I reported while building SQLBuild on Polyglot.
- **[SQLGlot](https://github.com/tobymao/sqlglot)** by Toby Mao and contributors, for years of work on SQL transpilation that this space builds on.

Both are MIT licensed. Their licence texts are in [THIRD_PARTY_NOTICES](THIRD_PARTY_NOTICES) and ship with every release.

SQLBabel goes a different way from both on translation. It doesn't rewrite the tree and print it out. It checks each rule against recorded warehouse results and refuses what it can't prove.

---

Built in Rust. Free and open source. [Apache 2.0](https://github.com/sqlstack-io/sqlbabel/blob/main/LICENSE).

Questions and feedback are welcome on [Discord](https://discord.com/invite/gATNYuBK6).

Part of [SQLStack](https://sqlstack.io/).

