A compact SQL formatter with dialect-aware parsing.
Project description
sql-neatfmt
sql-neatfmt is a compact SQL formatter designed for editor use.
It uses SQLGlot for dialect-aware parsing and owns the final layout rules.
The formatter intentionally favors readable query editing:
SELECT a.id,
a.name,
b.code code_name
FROM table_a a
LEFT JOIN table_b b
ON a.id = b.a_id
AND b.deleted = 0
WHERE a.status = 1
AND a.created_at >= DATE '2026-04-01'
GROUP BY a.id
ORDER BY a.id DESC;
Installation
Install the published package from PyPI:
uv tool install sql-neatfmt
Other common options:
pipx install sql-neatfmt
python -m pip install sql-neatfmt
Install from a Git checkout when you want the latest unreleased main:
uv tool install git+https://github.com/LuciusChen/sql-neatfmt
Install from a local checkout while developing:
uv tool install --from ~/repos/sql-neatfmt sql-neatfmt
Usage
sql-neatfmt --dialect mysql < query.sql
sql-neatfmt --dialect postgres query.sql
sql-neatfmt --dialect oracle --fix query.sql
sql-neatfmt --dialect mysql --keyword-case lower query.sql
sql-neatfmt --dialect mysql --check query.sql
sql-neatfmt --dialect mysql --diff query.sql
Keywords are uppercased by default. Use --keyword-case lower or
--no-uppercase-keywords to emit lowercase keywords instead.
Use --check in CI or editor hooks to fail when SQL would be reformatted.
Use --diff to print a unified diff without modifying files.
Review Corpus
Broader style samples live under review-cases/{dialect}/. These are intended
for human review before a style rule is promoted into tests/fixtures/.
Render the current formatter output locally:
uv run python scripts/render_review.py review-cases/mysql review-output/mysql
uv run python scripts/render_review.py review-cases/postgres review-output/postgres
uv run python scripts/render_review.py review-cases/oracle review-output/oracle
review-output/ is ignored by Git. After a rendered case has been reviewed and
accepted, promote it to a regression fixture:
uv run python scripts/accept_case.py oracle pivot_subquery \
review-cases/oracle/015-pivot.sql \
review-output/oracle/015-pivot.sql
Release
Build release artifacts:
uv build --no-sources
Publish to PyPI from GitHub Actions:
- Create a PyPI pending trusted publisher for
sql-neatfmt. - Use owner
LuciusChen, repositorysql-neatfmt, workflowpublish.yml, and environmentpypi. - Run the
Publishworkflow from GitHub Actions, or publish a GitHub release.
Publish from this checkout after setting a PyPI token:
uv publish --check-url https://pypi.org/simple/
Supported initial dialect names follow SQLGlot: mysql, postgres, oracle,
sqlite, tsql, and others accepted by SQLGlot.
Scope
This is intentionally conservative. Parse failures, block comments, and
templated SQL are returned unchanged rather than risk corrupting the query.
Line comments using -- are supported for common editor formatting cases.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sql_neatfmt-0.1.3.tar.gz.
File metadata
- Download URL: sql_neatfmt-0.1.3.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c1a81e75b971a4599634ef903c267686953aa98863c391a3d5274dd7f7db8fa
|
|
| MD5 |
72f09bf08700068aae6a9b3a56481016
|
|
| BLAKE2b-256 |
3672eeaa73e3ca241efdf50091b4490a11f43013df678b2f8a5e9dcfa8a883ab
|
Provenance
The following attestation bundles were made for sql_neatfmt-0.1.3.tar.gz:
Publisher:
publish.yml on LuciusChen/sql-neatfmt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_neatfmt-0.1.3.tar.gz -
Subject digest:
2c1a81e75b971a4599634ef903c267686953aa98863c391a3d5274dd7f7db8fa - Sigstore transparency entry: 1458476417
- Sigstore integration time:
-
Permalink:
LuciusChen/sql-neatfmt@1991f345efd40a1e68e09ad87d9d5645acaac14a -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/LuciusChen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1991f345efd40a1e68e09ad87d9d5645acaac14a -
Trigger Event:
release
-
Statement type:
File details
Details for the file sql_neatfmt-0.1.3-py3-none-any.whl.
File metadata
- Download URL: sql_neatfmt-0.1.3-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f022f916db04b803aaf13310b773030b640b01690a9101adf52e61a5ace94453
|
|
| MD5 |
eeaf10d8e3bbef80bac54828a2af57d7
|
|
| BLAKE2b-256 |
38584c10aba0b1e0031e1cc04b835e3c3354348c3d4110f650966fc902256d16
|
Provenance
The following attestation bundles were made for sql_neatfmt-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on LuciusChen/sql-neatfmt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_neatfmt-0.1.3-py3-none-any.whl -
Subject digest:
f022f916db04b803aaf13310b773030b640b01690a9101adf52e61a5ace94453 - Sigstore transparency entry: 1458476485
- Sigstore integration time:
-
Permalink:
LuciusChen/sql-neatfmt@1991f345efd40a1e68e09ad87d9d5645acaac14a -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/LuciusChen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1991f345efd40a1e68e09ad87d9d5645acaac14a -
Trigger Event:
release
-
Statement type: