sql-formatter
A SQL formatter
What it is and what it does
sql-formatter is a Python-based command-line and library tool that reformats SQL queries into a standardized, readable layout. It uses indentation and case normalization (uppercasing keywords, lowercasing identifiers) to enhance readability and make query structure immediately apparent. The formatter handles SELECT and CREATE TABLE/VIEW statements, including subqueries and joins, and can be invoked from the command line on individual files or batches, integrated into pre-commit hooks, or called directly from Python code.
The package includes basic validation to catch common mistakes like forgotten semicolons, unbalanced parentheses, and mismatched CASE/WHEN/END blocks. It does not parse SQL into data structures, validate queries against a specific database system, or format other SQL commands like INSERT or UPDATE. The project is no longer actively maintained as of April 2022, so it may not reflect current SQL standards or work seamlessly with the latest Python versions.
Use it for:
- Format SQL files in a pre-commit hook to enforce consistent styling across a team's repository.
- Reformat ad-hoc or poorly formatted SQL queries in Python scripts to improve readability before review or deployment.
- Batch-process a directory of SQL files to standardize indentation and keyword casing across a legacy codebase.
- Integrate into a data pipeline to normalize query formatting for logging or audit purposes.
- Use as a command-line tool to quickly beautify SQL files during development without leaving the terminal.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Reformats SQL queries into standardized, readable form with consistent indentation, capitalization, and line breaks, handling SELECT and CREATE statements with subqueries.
Yes, if you need a lightweight, dependency-free SQL formatter for SELECT and CREATE statements and can tolerate an unmaintained codebase. The permissive Apache license and zero runtime dependencies make it low-friction to add. However, do not rely on it for production systems handling modern SQL dialects or requiring ongoing support—test thoroughly with your SQL patterns first, and consider alternatives if you need active maintenance or broader SQL command support.
Install
sql-formatter on PyPI
pip
pip install sql-formatteruv
uv add sql-formatterpoetry
poetry add sql-formatterInstalling sql-formatter
Before you install
No runtime dependencies and a pure-Python wheel distribution make installation straightforward. However, the project has been abandoned since April 2022 with no updates for nearly two years, so maintenance and compatibility with newer Python versions or SQL dialects is not guaranteed.
License in practice
Licensed under Apache Software License 2.0 (permissive), so you may use, modify, and distribute the package freely in both open-source and commercial projects with minimal restrictions.
Quickstart
pip install sql-formatter
from sql_formatter.core import format_sql
formatted = format_sql("select a, b from table1 where a = 1")
print(formatted)
Requires Python 3.6 or later. SQL statements must end with a semicolon for the formatter to work correctly.
Verify before relying
- Whether the formatter handles modern SQL dialects (PostgreSQL, BigQuery, Snowflake, etc.) or only generic SQL syntax.
- Whether the package works reliably with Python versions newer than 3.8, given the abandonment status.
- Performance characteristics when formatting very large SQL files or deeply nested subqueries.
Package facts
| License | Apache Software License 2.0 (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,931 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 854,612/month — #4,894 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sql_formatter-0.6.2-py3-none-any.whl
Keywords: SQL, formatter
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
sqlvalidatorFormats, validates, and checks SQL SELECT…
permissive · top 15,000 on PyPI
pgsanityPgSanity validates PostgreSQL SQL syntax by…
permissive · top 15,000 on PyPI
sqlglotSQLGlot parses, transpiles, optimizes, and…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
sqlglotrsA SQL parser, transpiler, and optimizer that…
permissive · top 5,000 on PyPI
config-formatterAutomatically formats .ini and .cfg…
permissive · top 15,000 on PyPI
moz-sql-parserParses SQL queries into JSON-serializable parse…
copyleft · top 15,000 on PyPI
shandy-sqlfmtA command-line SQL formatter that automatically…
permissive · top 5,000 on PyPI
acryl-sqlglotParses, transpiles, and optimizes SQL across 23…
permissive · top 15,000 on PyPI
sqlglotcProvides mypyc-compiled C extensions that…
permissive · top 5,000 on PyPI