Skip to main content

SQL Formatter (localtools)

Lint, auto-fix and format SQL in 28 dialects with sqlfluff, and transpile between dialects with sqlglot. Runs on your machine: a one-page web UI on http://127.0.0.1:47117, plus a CLI for scripts and CI.

Install

OS command
Windows (PowerShell) irm https://raw.githubusercontent.com/chayprabs/localtools/main/sql-formatter/install.ps1 | iex
macOS / Linux curl -fsSL https://raw.githubusercontent.com/chayprabs/localtools/main/sql-formatter/install.sh | bash
PyPI pipx install localtools-sql-formatter

The script installs a self-contained build (bundled Python) into ~/.localtools/sql-formatter and adds a launcher.

Use

localtools-sql-formatter opens the UI. Paste SQL or drop .sql files (several at once), pick the dialect, then:

  • Lint: every violation with line:column, rule code (linked to the sqlfluff docs) and whether it can be auto-fixed. Download the report as JSON.
  • Fix: the fixed SQL with a diff, Copy and Download, plus what still needs a human.
  • Transpile: rewrite between dialects (e.g. T-SQL TOP/ISNULL to Postgres LIMIT/COALESCE), with notes on unsupported constructs.

Options: rule selection/exclusion (LT01,CP01, core, layout, names, legacy aliases and wildcards), templater (Raw, Jinja, or placeholders :name, ?, $1, $name, %(name)s, %s), and an uploaded .sqlfluff / setup.cfg / tox.ini / pyproject.toml. Config/default uses SQLFluff's Jinja default unless the uploaded config chooses another templater. Unknown rule selectors and placeholder styles are rejected.

localtools-sql-formatter lint models/*.sql --dialect postgres --format json   # or human | sarif; exit 1 on violations
localtools-sql-formatter fix query.sql --dialect snowflake                     # fixed SQL to stdout
localtools-sql-formatter fix *.sql --in-place --config .sqlfluff              # rewrite files; exit 1 if anything is left
localtools-sql-formatter fix - --diff < query.sql                             # stdin, unified diff
localtools-sql-formatter transpile q.sql --read tsql --write duckdb
localtools-sql-formatter dialects | rules

API: POST /api/lint, /api/fix, /api/transpile (multipart: sql and/or file..., dialect, rules, exclude_rules, templater, config file; transpile: read, write), GET /api/meta. /api/lint with format=sarif returns SARIF 2.1.0.

Engine and why

  • sqlfluff 4 (with its Rust parser, sqlfluffrs) is the most complete open-source SQL linter: dialect-aware parsing, ~70 rules, real auto-fix, Jinja/placeholder templating. Results are identical to the sqlfluff CLI with the same config (tested on TPC-H, sqlfluff's dialect fixtures, dbt's jaffle_shop and GitLab's schema).
  • fix repeats sqlfluff's fix pass until nothing changes, so running it twice gives the same SQL; when sqlfluff oscillates between two layouts (it happens), the tool settles on one of them deterministically.
  • sqlglot transpiles (sqlfluff cannot): it parses into an AST and regenerates SQL for 31 dialects. Output equals the python -m sqlglot --identify false CLI. It reformats in its own style, which is why lint/fix stay with sqlfluff.

Limits and safety

  • The web UI/API takes up to 512 KB of SQL and about 2,000 statements per run, and each run has a 120 s deadline (sqlfluff is thorough but slow: a messy 20 KB file can take 10+ s). Every run is a separate worker process that is killed at the deadline, when the browser disconnects, or when the server exits; at most 1–4 run at once (else HTTP 503). On Linux each worker is capped at 2 GB of memory. The CLI has no size limit or deadline.
  • Config files are parsed, never executed: library_path, macro/loader paths (any *_path / *_dir key), the python and dbt templaters and processes are ignored and listed in the result. sqlfluff's 20 KB "skip large file" default is off.
  • Files that do not parse are not fixed (like the sqlfluff CLI); the parse error shows line and column.
  • In-place fixes use an atomic replacement and retain the file mode, UTF-8 BOM and CRLF convention. Old crashed request folders are swept after one hour at startup; active owners and linked folders are preserved.

Cut

  • dbt templater (needs a dbt project, adapters and a database connection) and the python templater (runs code): use jinja, which provides dbt's ref/source/config builtins.
  • Automatic discovery of .sqlfluff files next to the SQL: pass --config explicitly.
  • winget/Homebrew/Scoop packages: Python-runtime tools ship through the install scripts and PyPI.

Update / uninstall

localtools-sql-formatter update · localtools-sql-formatter uninstall (pipx: pipx upgrade|uninstall localtools-sql-formatter).

License

MIT. Bundled components: see THIRD_PARTY_NOTICES.md.

Metadata

Release files for localtools-sql-formatter 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localtools-sql-formatter 1.0.2
File Size Uploaded Provenance Actions
localtools_sql_formatter-1.0.2.tar.gz 87.0 kB Without provenance Details for localtools_sql_formatter-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for localtools-sql-formatter 1.0.2
File Interpreter ABI Platform Actions
localtools_sql_formatter-1.0.2-py3-none-any.whl Python 3 none any Details for localtools_sql_formatter-1.0.2-py3-none-any.whl

Total release size: 177.6 kB

Release files / localtools_sql_formatter-1.0.2.tar.gz

Download URL localtools_sql_formatter-1.0.2.tar.gz
Size 87.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0279a9976c11c2ccc5ff8310c7eede18934ee5ac25bf8002e206ce9406c0bbd0
BLAKE2b-256 checksum
How to use checksums
807226ad4e332aa9e87e19e89d2d77fbc7c15151f6cb31ab8e8face9daf47727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / localtools_sql_formatter-1.0.2-py3-none-any.whl

Download URL localtools_sql_formatter-1.0.2-py3-none-any.whl
Size 90.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fa8a3c986779f41f9068bb01b785d8c32e73df94922a025cd6a5ddd46eb53d1
BLAKE2b-256 checksum
How to use checksums
e39da1eb176c1bb1cfa1301cad4d05881f6e575cd6858a73faacf003331bb835
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for localtools-sql-formatter 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page