Skip to main content

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:

  1. Create a PyPI pending trusted publisher for sql-neatfmt.
  2. Use owner LuciusChen, repository sql-neatfmt, workflow publish.yml, and environment pypi.
  3. Run the Publish workflow 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql_neatfmt-0.1.4.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sql_neatfmt-0.1.4-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file sql_neatfmt-0.1.4.tar.gz.

File metadata

  • Download URL: sql_neatfmt-0.1.4.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sql_neatfmt-0.1.4.tar.gz
Algorithm Hash digest
SHA256 03b84eea07b4cf3f024f9445cffef3548462480697a38c6bb846457964feba1d
MD5 17ca15dbf22b5a59316f16b6a671cb1a
BLAKE2b-256 5c1aa3bfc1812b16d0711e7c62cb7ae8646a7ee55e5831fe764da3fa0bfdcf52

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_neatfmt-0.1.4.tar.gz:

Publisher: publish.yml on LuciusChen/sql-neatfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sql_neatfmt-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: sql_neatfmt-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sql_neatfmt-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3c4e5b7711ef15361461b8f62076deb96f2fe42d4f0bfbc4f743801ac9340c38
MD5 29b9b3d8320ca7bdb6932b8dea32c672
BLAKE2b-256 6eb8c845a49527be6f7fb8d195d153b543bf526250bbea2c3ffdd7962b3b71a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_neatfmt-0.1.4-py3-none-any.whl:

Publisher: publish.yml on LuciusChen/sql-neatfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page