sqlparse
A non-validating SQL parser.
Decision gist · record as of 2026-08-14
Yes. sqlparse is actively maintained, has no dependencies, installs cleanly, and is widely used (top 1000 PyPI packages). It solves a real problem—parsing and formatting SQL without validation—and is the standard choice for this task in Python. No known vulnerabilities. Install it if you need to manipulate, format, or analyze SQL text programmatically.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction: pure Python wheel with no runtime dependencies.
- Active maintenance with a release 1 day ago and recent commits.
- Supports modern Python versions (3.10–3.14) and PyPy.
License · maintenance · safety
permissive license (permissive) — Licensed under the New BSD license (permissive). No restrictions on commercial or proprietary use; you may modify and redistribute under the same license terms.
last release 2026-08-13 (1 days) · last repo commit 2026-08-13 · 4,011 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 148,904,569 downloads/mo, #270 on PyPI
Alternatives
Verify before relying
pip install sqlparse
import sqlparse
# Split a script into statements
statements = sqlparse.split("select * from foo; select * from bar;")
# Format a statement
formatted = sqlparse.format("select id,name from users where active=1",
reindent=True, keyword_case="upper")
# Parse and inspect
stmt = sqlparse.parse("select id, name from users where active = 1")[0]
print(stmt.get_type())What it is and what it does
sqlparse is a non-validating SQL parser that accepts any SQL input and builds a tree representation of statements, clauses, identifiers, and expressions. It makes no assumptions about SQL dialect, so vendor extensions and templated SQL parse without error. The package provides three main functions: split() to break scripts into individual statements, format() to reindent and recase queries with options like keyword_case and strip_comments, and parse() to tokenize and walk the syntax tree.
It is designed as a building block for SQL formatters, linters, editors, and query analysis tools rather than a validator. The parsed tokens carry type information (ttype) for leaves, while groups can be descended into to represent nested constructs like subqueries and CASE expressions. A command-line tool (sqlformat) is also installed, and the package integrates with pre-commit hooks for automatic SQL file formatting.
Use it for
- Format SQL queries for readability with configurable indentation, keyword casing, and comment stripping.
- Split multi-statement SQL scripts into individual statements for batch execution or analysis.
- Build a SQL linter or style checker by walking the token tree to detect patterns or violations.
- Extract metadata from queries (e.g., table names, column references) by traversing parsed statements.
- Integrate SQL formatting into code editors or IDEs via the parse tree API.
- Preprocess templated or vendor-specific SQL before passing to a database driver.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
sqlparse is actively maintained, has no dependencies, installs cleanly, and is widely used (top 1000 PyPI packages). It solves a real problem—parsing and formatting SQL without validation—and is the standard choice for this task in Python. No known vulnerabilities. Install it if you need to manipulate, format, or analyze SQL text programmatically.
Install
sqlparse on PyPI
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a release 1 day ago and recent commits. Supports modern Python versions (3.10–3.14) and PyPy.
License in practice
Licensed under the New BSD license (permissive). No restrictions on commercial or proprietary use; you may modify and redistribute under the same license terms.
Quickstart
pip install sqlparse
import sqlparse
# Split a script into statements
statements = sqlparse.split("select * from foo; select * from bar;")
# Format a statement
formatted = sqlparse.format("select id,name from users where active=1",
reindent=True, keyword_case="upper")
# Parse and inspect
stmt = sqlparse.parse("select id, name from users where active = 1")[0]
print(stmt.get_type())
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 1 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 148,904,569 / month, #270 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: DatabaseTopic :: Software Development |
Evidence: sqlparse-0.6.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “sql linter building block”
- sqlparsesqlparse tokenizes SQL text into a tree of statements, clauses, and…
- squawk-cliLinter that analyzes PostgreSQL migrations and SQL statements to…
- rstcheckValidates reStructuredText syntax and checks code blocks nested…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also pglast · sqllineage · collate-sqllineage · moz-sql-parser · sqloxide · syntaqlite · fugue-sql-antlr · sqlglot · sqlvalidator · sql-formatter