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/ISNULLto PostgresLIMIT/COALESCE), with notes on unsupported constructs.
Options: rule selection/exclusion (LT01,CP01, core, layout), templater (Jinja, or placeholders :name, ?, $1, %(name)s, @name), and an uploaded .sqlfluff / setup.cfg / tox.ini / pyproject.toml.
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
sqlfluffCLI with the same config (tested on TPC-H, sqlfluff's dialect fixtures, dbt's jaffle_shop and GitLab's schema). fixrepeats 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 falseCLI. 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/*_dirkey), the python and dbt templaters andprocessesare 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.
Cut
- dbt templater (needs a dbt project, adapters and a database connection) and the python templater (runs code): use
jinja, which provides dbt'sref/source/configbuiltins. - Automatic discovery of
.sqlflufffiles next to the SQL: pass--configexplicitly. - 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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| localtools_sql_formatter-1.0.0.tar.gz | 84.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| localtools_sql_formatter-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 172.5 kB
Release files / localtools_sql_formatter-1.0.0.tar.gz
| Download URL | localtools_sql_formatter-1.0.0.tar.gz |
|---|---|
| Size | 84.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7935b91dd1e2465238bff9df7890d224a4d2a2477fb84ac20ed3dfd3b9481786
|
|
BLAKE2b-256 checksum How to use checksums |
153812961b3f6919dab1abbaee50ff2f9371fe8b6dd35adf021fa6cc381673a5
|
| 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.0-py3-none-any.whl
| Download URL | localtools_sql_formatter-1.0.0-py3-none-any.whl |
|---|---|
| Size | 88.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72fa93bec621cb8088fe845f525e81841953629ec6ebc93513315c657b72acae
|
|
BLAKE2b-256 checksum How to use checksums |
955d64b98928bcbff0dba7b4e9c91014851e7463ba30383ca63e6b6f40f00b2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|