sqlparse

A non-validating SQL parser and formatter for Python

Library
PyPI
v0.6.0
4,014stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
81/100Excellent
Development Activity88
Maintenance48
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture76
Code Quality78
Innovation60
Learning Curve82

sqlparse is a Python library for parsing, splitting, and formatting SQL statements without validating them against a specific database dialect’s grammar. It tokenizes raw SQL text into a navigable tree of statements, tokens, and identifiers, and exposes a format() function for reindenting, keyword-case normalization, and other cosmetic rewrites.

Because it doesn’t attempt to validate SQL correctness or target one specific database engine, sqlparse works across dialects and is widely embedded as a dependency by other tools - notably Django Debug Toolbar, ipython-sql, and various SQL linting/formatting utilities - as well as usable directly as a pre-commit hook for formatting SQL files before commit.

What You Get

  • sqlparse.parse() producing a navigable token tree for any SQL statement
  • sqlparse.split() for splitting multi-statement SQL strings
  • sqlparse.format() with options for reindenting, keyword case, and comment stripping
  • A pluggable lexer/filter pipeline (sqlparse.filters, sqlparse.engine) for custom formatting rules
  • A sqlparse CLI entry point for formatting SQL files from the command line
  • Usable directly as a pre-commit hook for automatic SQL formatting in CI

Common Use Cases

  • Pretty-printing raw SQL queries in debugging tools like Django Debug Toolbar
  • Splitting a file of multiple SQL statements before executing them one at a time
  • Building custom SQL linters or formatters on top of the parsed token tree
  • Normalizing keyword casing and indentation in a codebase’s SQL migration files
  • Powering IDE or notebook tools (e.g. ipython-sql) that need to inspect SQL structure

Under The Hood

Architecture - sqlparse/lexer.py tokenizes raw SQL text using regex rules defined in keywords.py, sqlparse/engine groups tokens into a Statement tree via a pipeline of StatementFilter/grouping filters, sqlparse/sql.py defines the token/statement classes exposed to users, and sqlparse/filters implements the transformations (reindent, case normalization, comment stripping) that formatter.py composes into the public format() function.

Tech Stack - Pure Python with no runtime dependencies, targeting Python 3.8+, packaged with a standard pyproject.toml build, and shipping a py.typed marker for type-checker compatibility; cli.py/__main__.py provide a lightweight python -m sqlparse command-line entry point.

Code Quality - An extensive tests/ directory covers tokenization, grouping, formatting options, and CLI behavior; the project has a long history (created 2012, 1,363 total commits) with slowed but ongoing maintenance (moderate activity, ~2.3 commits/month), and BSD-3-Clause licensing with no unusual constraints.

API Design - The three-function surface (split, parse, format) covers the vast majority of use cases with minimal ceremony, and the token tree returned by parse() follows a consistent, well-documented class hierarchy (Statement -> Token/TokenList) that has remained stable enough for downstream tools like Django Debug Toolbar to depend on it for over a decade.

Used by 13 apps in this directory

Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
Python
68%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,687

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
67
Dependency
Built with
Python68%
TypeScript31%
Updated today
C++
69%
Apache 2.0

ClickHouse

Databases · Analytics · Data Engineering

49,325

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
C++69%
Python13%
Updated today
TypeScript
40%
MIT

FeatBit

Devops · Developer Tools

1,902

Self-hosted, enterprise-grade feature flag platform for safe, targeted, and data-driven feature releases.

View details
89
Repo Health
78
Technical
70
Dependency
Built with
TypeScript40%
C#37%
Updated today
HTML
48%
LGPL-2.1

Horilla

Human Resources · ERP

1,330

Open-source HRMS covering recruitment, attendance, payroll, and biometrics in one self-hosted Django application.

View details
88
Repo Health
60
Technical
65
Dependency
Built with
HTML48%
Python35%
JavaScript13%
Updated today
Python
58%
Apache 2.0

MLflow

AI Development · Monitoring

27,573

The open source AI engineering platform for debugging, evaluating, monitoring, and optimizing production LLMs and agents at scale.

View details
97
Repo Health
86
Technical
68
Dependency
Built with
Python58%
TypeScript33%
Updated today
TypeScript
55%
Other

Phase Console

Security · Devops

904

End-to-end encrypted secrets management for engineering teams — from local dev to Kubernetes production.

View details
84
Repo Health
73
Technical
67
Dependency
Built with
TypeScript55%
Python44%
Updated today
Python
55%
Other

PostHog

Analytics · Monitoring · Developer Tools

37,777

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
67
Dependency
Built with
Python55%
TypeScript36%
Updated today
Python
45%
Other

Redash

Analytics · Data Engineering

28,754

Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.

View details
85
Repo Health
74
Technical
61
Dependency
Built with
Python45%
JavaScript31%
TypeScript17%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search