sqlfmt
sqlfmt is an opinionated Python-based command-line tool that automatically formats your dbt SQL files and other SQL statements. Similar to `black` for Python, it enforces a consistent style with minimal configuration, primarily line length. It is currently at version 0.29.0 and maintains an active release cadence with frequent updates.
Warnings
- breaking sqlfmt now requires Python 3.10 or newer. Users on older Python versions will need to upgrade their environment.
- gotcha sqlfmt is an alpha product and might not always produce the desired formatted output, or could potentially break SQL syntax. It is strongly recommended to run it on files in a version control system and commit changes before running sqlfmt.
- breaking When writing formatted code to stdout, sqlfmt no longer includes an extra trailing newline. This may affect scripts or tools that expect an additional newline when piping `sqlfmt` output.
- gotcha sqlfmt is opinionated and not configurable beyond line length. It enforces a single style. If you require highly customizable formatting rules, sqlfmt may not be suitable.
Install
-
pip install shandy-sqlfmt -
pipx install shandy-sqlfmt -
pipx install shandy-sqlfmt[jinjafmt]
Quickstart
# To format all .sql and .sql.jinja files in the current directory and subdirectories: sqlfmt . # To see a diff of changes sqlfmt would make (without modifying files): sqlfmt --diff . # To format SQL from stdin and print to stdout: echo "select 1,2,3 from my_table where a=1" | sqlfmt -