SQLGlot is a Python-based SQL parser, transpiler, optimizer, and execution engine that operates with no external dependencies. The project supports translation between 31 different SQL dialects including DuckDB, Presto, Trino, Spark, Databricks, Snowflake, BigQuery, PostgreSQL, MySQL, Redshift, Hive, ClickHouse, and SQLite. Its primary purpose is to read diverse SQL inputs and output syntactically and semantically correct SQL in target dialects, making it valuable for cross-database query migration and standardization.
The repository implements a comprehensive generic SQL parser backed by a robust test suite and demonstrates strong performance despite being written entirely in Python. Core capabilities include SQL formatting, dialect translation, syntax error detection, query optimization, abstract syntax tree manipulation, and programmatic SQL construction. The parser can identify various syntax errors such as unbalanced parentheses and incorrect keyword usage, with dialect incompatibilities configurable to warn or raise exceptions based on user settings.
SQLGlot's architecture centers on expression tree traversal and manipulation. Users can parse SQL into an abstract syntax tree, analyze queries to extract metadata like columns and tables, modify parsed trees programmatically, and transform expressions recursively. The optimizer performs multiple rewriting techniques to create canonical AST representations, useful for standardizing queries or building query engines. The project also supports custom dialect creation through subclassing the Dialect class, enabling users to extend support for proprietary or specialized SQL variants.
The repository demonstrates active maintenance and community engagement. Enhancement requests and PostgreSQL-related issues represent the most active issue categories.
SQLGlot is widely adopted across the data and analytics industry. Known users include SQLMesh, Apache Superset, Dagster, Fugue, Ibis, dlt, mysql-mimic, Querybook, Quokka, Splink, and SQLFrame. The project uses semantic versioning where patch versions indicate backwards-compatible changes, minor versions indicate backwards-incompatible additions, and major versions indicate significant breaking changes.
The project provides comprehensive documentation through pdoc-generated API references hosted on sqlglot.com, along with educational resources including an AST primer, onboarding documentation, and posts on topics like building Python SQL engines and semantic SQL diffing. Installation is available via PyPI with optional development dependencies. The codebase includes benchmarking utilities comparing SQLGlot's parsing performance against other Python-based parsers and Rust bindings. A community Slack channel facilitates user engagement and support.