skillfed

shandy-sqlfmt

sqlfmt formats your dbt SQL files so you don't have to.

shandy-sqlfmt v0.32.0 1.4M downloads/30d#3,932 on PyPI542
Permissive license Apache-2.0 Active released

What it is and what it does

This package is a fast, opinionated SQL formatter built for dbt projects and other SQL codebases. It works by lexing SQL into tokens and reformatting to a single enforced style, without requiring a full SQL parser. This approach makes it much faster than traditional linters and easier to maintain. The tool formats select, delete, grant, revoke, and create function statements, preserves comments and some whitespace, and works with Jinja templates embedded in SQL.

It integrates with dbt, pre-commit, VSCode, and CI systems. Configuration is minimal—line length and dialect choice (polyglot by default, with special handling for ClickHouse). The package depends on click, jinja2, platformdirs, tomli, and tqdm for CLI, templating, configuration, and progress display.

Use it for:

  • Enforce consistent SQL style across a dbt project without manual code review discussions
  • Format SQL files automatically in pre-commit hooks or CI/CD pipelines before deployment
  • Quickly reformat legacy or inconsistently-styled SQL codebases to a standard format
  • Format Jinja-templated SQL files while preserving template logic
  • Check SQL formatting compliance in CI without modifying files using --check mode

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A command-line SQL formatter that automatically reformats SQL files to a consistent style, similar to Black for Python or gofmt for Go.

Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and fills a clear need for SQL formatting in dbt and analytics workflows. The Apache-2.0 license poses no restrictions. Start with a version-controlled repository and use --check or --diff on first run to verify output before committing changes.

Install

shandy-sqlfmt on PyPI

pip

pip install shandy-sqlfmt

uv

uv add shandy-sqlfmt

poetry

poetry add shandy-sqlfmt

Installing shandy-sqlfmt

Before you install

Low install friction with a pure Python wheel and five lightweight runtime dependencies. Actively maintained with a release 4 days ago and steady repository activity.

License in practice

Licensed under Apache-2.0 (permissive), allowing use in commercial and private projects with minimal restrictions.

Quickstart

pip install "shandy-sqlfmt[jinjafmt]"

# Format SQL files in current directory
sqlfmt .

# Check formatting without modifying files
sqlfmt --check .

# Format from stdin
echo "select 1" | sqlfmt -

Requires Python 3.10 or above. The PyPI package name is shandy-sqlfmt, not sqlfmt.

Verify before relying

  • Whether formatted output is always syntactically valid or if edge cases can break SQL
  • Performance characteristics when formatting very large files or projects
  • Completeness of support for SQL dialects beyond the documented ClickHouse special case

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 5 — click, jinja2, platformdirs, tomli, tqdm
Maintenance actively maintained — 4 days since the last release
Last repo commit
First released
Downloads 1,415,027/month — #3,932 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: shandy_sqlfmt-0.32.0-py3-none-any.whl

Operating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: SQLTopic :: Software Development :: Quality AssuranceTyping :: Typed

Tags

sql formatterdbt sql formattingauto-format sql codesql code stylejinja sql formattingsql beautifiersql formatting tool
sql-formattingdbt-toolscode-style

More Quality Assurance packages