python-sqlparse

A non-validating SQL parser for Python. Split scripts into statements, format them, and walk their token tree.

sqlparse tokenizes SQL text and groups the parts it recognizes into a tree of statements, clauses, identifiers and expressions. It accepts any input without validating it, and makes no assumptions about a particular SQL dialect, so vendor extensions and templated SQL parse too. It is a building block for formatters, linters, editors and query analysis tools.

Requires Python 3.10+. Licensed under the New BSD license.

Contents

Resources

Project page

https://github.com/andialbrecht/sqlparse

Bug tracker

https://github.com/andialbrecht/sqlparse/issues

Documentation

https://sqlparse.readthedocs.io/

Online Demo

https://sqlformat.org/