DEV.co
Open-Source Databases · tobymao

sqlglot

SQLGlot is a Python SQL parser and transpiler that converts SQL queries between 31 different database dialects (DuckDB, Snowflake, BigQuery, Spark, Presto, etc.). It provides zero-dependency parsing, optimization, and formatting capabilities with a comprehensive test suite and pure-Python implementation.

Source: GitHub — github.com/tobymao/sqlglot
9.4k
GitHub stars
1.2k
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorytobymao/sqlglot
Ownertobymao
Primary languagePython
LicenseMIT — OSI-approved
Stars9.4k
Forks1.2k
Open issues4
Latest releaseUnknown
Last updated2026-07-08
Sourcehttps://github.com/tobymao/sqlglot

What sqlglot is

Pure-Python SQL parser and code generator supporting 31 dialects with optional mypyc C extensions. Provides AST traversal, expression tree manipulation, syntax error detection, dialect-specific function translation, and query optimization. No external dependencies required; optional C compilation for performance.

Quickstart

Get the sqlglot source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/tobymao/sqlglot.gitcd sqlglot# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Multi-dialect SQL transpilation

Automatically convert SQL queries between platforms (e.g., Spark to Snowflake, DuckDB to BigQuery) while handling dialect-specific syntax, functions, and data types.

SQL query analysis and transformation

Parse SQL into AST for metadata extraction (columns, tables, joins), validation, optimization, and programmatic query building and modification.

SQL formatting and standardization

Normalize SQL syntax across teams, preserve comments, handle identifier delimiters, and detect syntax errors with structured error reporting.

Implementation considerations

  • Dialect must be explicitly specified for both parsing (read) and output (write); default behavior uses a generic SQLGlot dialect. Omitting dialect is a common source of parse failures.
  • Test suite coverage is comprehensive; validate against your specific SQL patterns and dialect combinations before production use.
  • Optional C extension (mypyc compilation) available via `pip install sqlglot[c]` for performance; pure Python fallback always available.
  • Parser error detection includes unbalanced parentheses and reserved keyword misuse; configure `unsupported_level` (WARN/RAISE/IMMEDIATE) for dialect incompatibility handling.
  • No latestRelease field in data; verify version compatibility and changelog on PyPI; last push to main was 2026-07-08.

When to avoid it — and what to weigh

  • Runtime SQL execution required — SQLGlot parses and transpiles SQL but does not execute queries. For execution, pair with a database driver or use SQLFrame (standalone library mentioned for PySpark operations).
  • Highly proprietary or undocumented SQL dialects — Limited to 31 supported dialects. Custom or vendor-specific extensions may require custom dialect implementation or may not be fully supported.
  • Performance-critical real-time parsing at massive scale — Pure Python with optional C extensions provides good performance, but compiled database-native parsers may be faster for extremely high-throughput scenarios.

License & commercial use

MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with minimal restrictions. Attribution appreciated but not legally required.

MIT License explicitly permits commercial use in proprietary products without royalties or disclosure requirements. No copyleft obligations. Suitable for internal tools and SaaS products. Review terms if bundling with other GPL or copyleft libraries.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Parser input validation catches syntax errors and structural issues (unbalanced parentheses, invalid keywords). No inherent SQL injection protection; SQLGlot parses and transpiles but does not sanitize or execute. Input validation is limited to syntactic correctness. Use parameterized queries and input sanitization at the application layer. No known security audit or third-party security review mentioned in provided data.

Alternatives to consider

sqlparse (Python)

Simpler Python SQL parser; lower coverage of edge cases and dialects. Choose if lightweight parsing suffices; SQLGlot better for multi-dialect transpilation and AST manipulation.

Presto/Trino SQL parser (Java-based)

Native parser for Presto/Trino; higher accuracy for those dialects but requires JVM and lacks transpilation to other targets. Choose if Presto/Trino is sole target and Python integration acceptable.

Apache Calcite (Java)

Comprehensive SQL parser and optimizer with broad dialect support; heavyweight compared to SQLGlot. Choose for complex optimization or if Java ecosystem already in use.

Software development agency

Build on sqlglot with DEV.co software developers

SQLGlot handles SQL dialect conversion, formatting, and analysis with minimal dependencies. Get started with pip install sqlglot and evaluate against your real SQL workloads.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

sqlglot FAQ

Why does parsing fail for valid SQL?
Most commonly, source dialect is not specified. Use `parse_one(sql, dialect='spark')` or `transpile(sql, read='spark', write='duckdb')` to explicitly set input dialect. Default SQLGlot dialect is a superset but may not match all proprietary syntax.
Can I execute SQL with SQLGlot?
No. SQLGlot parses, transpiles, and optimizes but does not execute queries. For Spark DataFrame operations, use SQLFrame library. For other databases, use native drivers after transpiling.
What about PySpark dataframe support?
PySpark dataframe API was moved to standalone SQLFrame library in v24. It allows query execution in addition to SQL generation. Import and use SQLFrame separately if needed.
How do I handle transpilation errors between dialects?
Set `unsupported_level` to WARN (default, best-effort), RAISE (exception on incompatibility), or IMMEDIATE. Warnings indicate features not fully supported in target dialect but translation proceeds.

Software development & web development with DEV.co

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If sqlglot is part of your open-source databases roadmap, our team can implement, customize, migrate, and maintain it.

Standardize SQL Across Your Stack

SQLGlot handles SQL dialect conversion, formatting, and analysis with minimal dependencies. Get started with pip install sqlglot and evaluate against your real SQL workloads.