python-sqlparse
Port variant v14
Summary Non-validating SQL parser (3.14)
Package version 0.6.0
Homepage https://github.com/andialbrecht/sqlparse
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants v13
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 19 AUG 2026, 18:47:48 UTC
Port created 01 APR 2019, 21:34:39 UTC
Subpackage Descriptions
single # sqlparse [Build Status] [Coverage] [Documentation] [PyPI] [Python versions] [License] 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. Licensed under the [New BSD license]. ## Install `bash pip install sqlparse ` ## Usage Three module-level functions cover most needs: `split()`, `format()` and `parse()`. ### Split a script into statements ```python import sqlparse sqlparse.split("select * from foo; select * from bar;") # ['select * from foo;', 'select * from bar;'] ``` ### Format a statement ```python print(sqlparse.format("select id,name from users where active=1", reindent=True, keyword_case="upper")) ` `sql SELECT id, name FROM users WHERE active=1 ``` `format()` accepts the same options as the command line, among them `reindent`, `keyword_case`, `strip_comments` and `indent_width`. ### Parse and inspect a statement ```python statement = sqlparse.parse("select id, name from users where active = 1")[0] print(statement.get_type()) for token in statement.tokens: if not token.is_whitespace: print(f"{token.ttype or type(token).__name__!s:20} {token!s}") ` ` SELECT Token.Keyword.DML select IdentifierList id, name Token.Keyword from Identifier users Where where active = 1 ``` Tokens with a `ttype` are leaves. The others are groups you can descend into, which is how nested constructs like subqueries and `CASE` expressions are represented. See [Analyzing SQL statements] for the traversal API. ## Command line Installing sqlparse also provides the `sqlformat` command. It reads from stdin when the filename is `-`, writes to stdout by default, and rewrites files in place with `--in-place`: ```bash sqlformat --reindent --keywords upper query.sql ```
Configuration Switches (platform-specific settings discarded)
PY313 OFF Build using Python 3.13 PY314 ON Build using Python 3.14
Package Dependencies by Type
Build (only) python314:dev:std
python-pip:single:v14
autoselect-python:single:std
Build and Runtime python314:primary:std
Download groups
main mirror://PYPIWHL/d9/50/f00935da0ec7cbf325f8dc4f772ae46fbc7b672dd62876e73f0a94adda57
Distribution File Information
b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f 50070 python-src/sqlparse-0.6.0-py3-none-any.whl
Ports that require python-sqlparse:v14
python-Django:v14 High-level Python Web framework (3.14)
python-django-debug-toolbar:v14 Debug info of current request/response (3.14)