sqlparse is a non-validating SQL parser for Python, providing support for parsing, splitting, and formatting SQL statements. The current version is 0.5.5, released on March 28, 2026, with a release cadence of approximately every 6 months.
pip install sqlparseVerified import paths — ran on the pinned version, not inferred.
A quickstart guide demonstrating how to split, format, and parse SQL statements using sqlparse.
Install sqlparse using pip: pip install sqlparse
pip install sqlparse
Pass formatting options directly as keyword arguments, for example: `sqlparse.format(sql_string, reindent=True, keyword_case='upper')`.
Check if a token is a group using `token.is_group` before attempting to access its `tokens` attribute or iterating over it. For example:
```python
import sqlparse
sql = 'SELECT * FROM foo;'
parsed = sqlparse.parse(sql)[0]
for token in parsed.tokens:
if token.is_group:
print(f"Group: {token.normalized}")
for subtoken in token.tokens:
print(f" Subtoken: {subtoken.normalized}")
else:
print(f"Token: {token.normalized}")
```