SQLGlot is a powerful Python library for parsing, transpiling, optimizing, and even executing SQL. It supports translating SQL across over 30 different database dialects, enabling cross-dialect compatibility, query parsing into Abstract Syntax Trees (ASTs), programmatic query rewriting, and optimization. It's known for being a fast, pure-Python solution with no external dependencies and is regularly among the top Python package downloads. The library is currently at version 30.1.0 and follows a versioning strategy where MINOR version increments can introduce backwards-incompatible changes.
Verified import paths — ran on the pinned version, not inferred.
Commonly imported directly for convenience; the root module also provides it.
Commonly imported directly for convenience; the root module also provides it.
The `exp` submodule contains all expression types for AST manipulation and is typically imported directly from the root `sqlglot` module now.
This quickstart demonstrates basic SQL parsing and cross-dialect transpilation. The `parse_one` function converts a SQL string into an Abstract Syntax Tree (AST), while `transpile` converts SQL between specified dialects. It also shows a common pattern for transforming MySQL-specific functions to BigQuery equivalents.
Breaking-change detection hasn't run for this library yet.
CVE tracking and dependency tree are planned for a later release.