Registry / database / sqlparse

sqlparse

JSON →
library0.6.0pypypi✓ verified 24d ago

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 sqlparse
INSTALL
IMPORT
SIG · SQLPARSE
S
sqlparse
databasepythonv0.6.0
Install
1.7s avg
Import
35ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.036s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.034s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sqlparse
import sqlparse
Ensure the module is installed in your environment

A quickstart guide demonstrating how to split, format, and parse SQL statements using sqlparse.

import sqlparse # Split a string containing two SQL statements: raw = 'SELECT * FROM foo; SELECT * FROM bar;' statements = sqlparse.split(raw) # Format the first statement and print it out: first = statements[0] print(sqlparse.format(first, reindent=True, keyword_case='upper')) # Parsing a SQL statement: parsed = sqlparse.parse('SELECT * FROM foo')[0] print(parsed.tokens)
Debug
Known issues
breakingEnsure that sqlparse is installed in your environment to avoid ImportError.
fix
Install sqlparse using pip: pip install sqlparse
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'sqlparse'
The 'sqlparse' library has not been installed in the current Python environment.
fix
pip install sqlparse
TypeError: format() got an unexpected keyword argument 'options'
The `sqlparse.format` function expects formatting options as direct keyword arguments, not as a dictionary passed via an 'options' parameter.
fix
Pass formatting options directly as keyword arguments, for example: `sqlparse.format(sql_string, reindent=True, keyword_case='upper')`.
AttributeError: 'Token' object has no attribute 'tokens'
When iterating through the tokens of a parsed SQL statement, not all tokens are `TokenList` (group) objects; simple `Token` objects do not have a `tokens` attribute.
fix
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}")
```
Upgrade
Version history
0.6.0latest on PyPI · released Aug 13, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.8 or higher
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
sqlparse — pip install sqlparse · libregistry