SQLFluff

4.1.0 · active · verified Thu Apr 09

SQLFluff is an SQL linter and auto-formatter designed for humans, with a focus on configurability and extensibility. It helps enforce coding styles and catch common errors in SQL queries across various dialects. The current version, 4.1.0, continues to expand its Rust-backed execution, improve performance, and enhance dialect support. It maintains an active release cadence with minor versions often introducing performance gains and bug fixes, and major versions bringing significant architectural shifts.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically lint and fix a SQL string using SQLFluff's Python API. It initializes a SQL string with style violations and then applies `lint()` to identify issues and `fix()` to automatically correct them based on the 'ansi' dialect. You can specify a different dialect if needed.

from sqlfluff import lint, fix

sql_string = "SELECT a , b FROM my_table"

# Lint the SQL string
linter_results = lint(sql_string, dialect='ansi')
print("Linting Results:")
for result in linter_results:
    print(result.as_dict()) # or result.to_string()

# Fix the SQL string
fixed_sql = fix(sql_string, dialect='ansi')
print("\nFixed SQL:")
print(fixed_sql)

view raw JSON →