Repo of the Day
sqlfluff/sqlfluff
Published: Jun 14, 2023
Open repository ↗A modular SQL linter and auto-formatter with support for multiple dialects and templated code.
Summary
SQLFluff is a Python-based SQL linter and auto-formatter that supports many database dialects and templated SQL. It is designed with ELT workflows in mind and can parse templated code such as Jinja and dbt. The tool flags style and structural issues in SQL files and can auto-fix most of them.
What it is useful for
Engineers working on SQL-heavy data projects often need consistent style across many files and dialects. SQLFluff helps by:
- Linting SQL for whitespace, indentation, capitalization, and other style rules against a configurable rule set.
- Auto-fixing many of those issues with
sqlfluff fix. - Supporting a long list of dialects, including ANSI, BigQuery, ClickHouse, Databricks, DuckDB, MySQL, Oracle, PostgreSQL, Redshift, Snowflake, SparkSQL, SQLite, Trino, T-SQL, and many more. The README notes that some dialects may not be fully supported.
- Parsing templated SQL, including Jinja, SQLAlchemy-style placeholders, Python format strings, and dbt. dbt support requires a separate plugin.
- Providing a VS Code extension and a Docker image for editor or CI use.
The README also notes that the Python API "is in a less stable state and may see more significant changes more often," so users relying on programmatic access should expect more churn between releases than the CLI.
How engineers can use it
The README documents a quick start:
- Install the package with
pip install sqlfluff. - Run
sqlfluff lint test.sql --dialect ansito see rule violations on a SQL file. The README example shows output flagging issues such as extra spaces, unwanted indentation, and missing trailing newlines. - Run
sqlfluff fix test.sql --dialect ansito apply auto-fixes. - For faster parsing, install the optional Rust-backed lexer and parser with
pip install sqlfluff[rs]. On supported CPython 3.10+ platforms this installs a prebuilt wheel; otherwise a Rust toolchain installed viarustupis required. - As alternatives, the README points to the official Docker image and an online playground.
For dbt projects, install the separate dbt templating plugin. For broader rule configuration, CI integration, and the full rules reference, the README directs readers to the documentation at docs.sqlfluff.com.