trino-sql-validator
Fast Trino SQL syntax validator — a Python library whose core is written in Rust and compiled to a native extension via PyO3 + maturin.
Installable from PyPI:
pip install trino-sql-validator
Quickstart
from trino_sql_validator import validate, validate_file
# A string with one or many statements
result = validate("SELECT 1; SELECT * FROM t WHERE a > 0;")
assert result.valid
assert result.statement_count == 2
# Invalid SQL returns a value, never raises
result = validate("SELECT * FORM t")
assert not result.valid
print(result.error) # e.g. "Expected: end of statement, found: FORM at line 1, column 10"
print(result.error.line) # 1
# Validate a file
result = validate_file("queries.sql", dialect="trino")
Invalid SQL (and files containing it) is returned as a ValidationResult;
it is not raised as an exception. Only genuine misuse (unknown dialect,
unreadable file) raises.
Catalog warnings (functions and data types)
For dialect="trino", validate() also checks that every function called and
every data type used in the SQL exists in the documented Trino catalog. Unknown
names are reported as non-fatal warnings — valid stays True because syntax
is fine:
result = validate("SELECT marh(1.5)") # round() misspelled
assert result.valid
print(result.warnings) # (FunctionWarning(name='marh', line=1, column=8),)
print(result.unknown_functions) # ['marh']
result = validate("CREATE TABLE t (a bignum, b bigint)") # bigint vs bignum
print(result.warnings[0]) # TypeWarning(name='bignum', line=1, column=19)
print(result.unknown_types) # ['bignum']
The catalogs are auto-generated from the Trino docs and only check name
existence, not argument counts, precision/scale, or semantic correctness.
hive/generic dialects skip these checks. False positives are possible if a
deployed Trino adds plugin functions/types beyond the docs.
dbt and Jinja templates
Jinja/dbt SQL is supported by default. validate() and validate_file() use
jinja="auto" to mask Jinja expressions, statements, and comments before
parsing while preserving line numbers and file structure. This supports
constructs such as {{ ref("orders") }} and {{ var("catalog") }} without
requiring a dbt installation or project context. Use jinja="mask" as an
explicit spelling of the same mode.
Use jinja="reject" to pass the original template directly to the SQL parser.
Masking cannot determine SQL generated by control-flow blocks, macros, or
adapter semantics; render those cases with dbt and validate the rendered SQL
for complete coverage.
Dialects
"trino"(default) — Trino-flavored with a custom override tuned for Presto/Trino syntax (LIMIT ALL, backslash escapes, etc.)."hive"and"generic"— offered as permissive alternates.
Known limitations
sqlparser-rs (the parser we use) performs syntax validation, not semantic
analysis. It may accept SQL that Trino would reject at analysis time (unknown
columns/tables, duplicate columns), and it can reject exotic Trino-specific DDL.
In particular, Trino's array(...) component-type syntax and deeply nested
row(...) types (e.g. row(a row(b bigint)) or array(row(x bigint))) are not
parsed by sqlparser, which only understands array<...>/map(...)/row(...)
at certain nesting levels. For the overwhelming majority of SELECT/DDL statements
the results are accurate. See plan/roadmap.md for the path
toward stricter Trino fidelity.
Development
See AGENTS.md for setup, internal conventions, and release steps.
Key commands:
python3 -m venv .venv && source .venv/bin/activate
pip install -U pip maturin && pip install -e ".[dev]"
maturin develop # build + install native ext into the venv
cargo test # Rust tests
pytest -q # Python tests
cargo fmt --check # formatting
cargo clippy --all-targets -- -D warnings
License
MIT
Release files for trino-sql-validator 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| trino_sql_validator-0.7.0.tar.gz | 50.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| trino_sql_validator-0.7.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| trino_sql_validator-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| trino_sql_validator-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| trino_sql_validator-0.7.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| trino_sql_validator-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 9.9 MB
Release files / trino_sql_validator-0.7.0.tar.gz
| Download URL | trino_sql_validator-0.7.0.tar.gz |
|---|---|
| Size | 50.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
758315da6e965aa19102919ba37856391a763cb1a4fa51e7c95aa65a12021578
|
|
BLAKE2b-256 checksum How to use checksums |
e20c964d231cd9ddf9af0d6b8205cf4f40373f38270131e883b7897dff972f80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / trino_sql_validator-0.7.0-cp310-abi3-win_amd64.whl
| Download URL | trino_sql_validator-0.7.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d064293699bdcab35867423727363aedc3363f8042c76029da92e6855f4594a9
|
|
BLAKE2b-256 checksum How to use checksums |
f5dd96d2d65976d87b064f73ad507cb2c263ddda9cd29bb35edce3dc6c7fc878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / trino_sql_validator-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trino_sql_validator-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
795ad400442cc38ad6cb1bdf7b54cfcd9f6626c57f3cdfe1cb20f915bf6ac207
|
|
BLAKE2b-256 checksum How to use checksums |
8c10f553adc7078be33ea4d173fc88eda77cd95b1515c922d21f7f676d4f7706
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / trino_sql_validator-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | trino_sql_validator-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
a04ae9a2f02b9519f63e4beb8c50d25a2b4063576431c104bc9ec33774912fe8
|
|
BLAKE2b-256 checksum How to use checksums |
a9d7e500f627baea2e54bf15f646180e55641b3d484a83f625f4701d43a7d140
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / trino_sql_validator-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | trino_sql_validator-0.7.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d03e6008d9c71c507f4607434f1e83495da7bed570d90739a13e5298c0209475
|
|
BLAKE2b-256 checksum How to use checksums |
bd75d9d95b788e71abda2fea220ec9a05d2092a7b826a70e66e3ca106f0352ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / trino_sql_validator-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | trino_sql_validator-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ed7ea60ebe57e7c302a9ffee2a68d9d49e82131181f31c6cf39847d034f383d3
|
|
BLAKE2b-256 checksum How to use checksums |
9efb7c96b21fc4286e21db1e3860294681d089fb8b97cd6124517b16c758f54c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency log