{"library":"sqlfluff-templater-dbt","title":"SQLFluff dbt Templater","type":"library","description":"SQLFluff-templater-dbt is a plugin for SQLFluff, the SQL linter for humans, specifically designed to correctly parse and compile SQL projects using dbt (data build tool). It extends SQLFluff's capabilities to lint dbt models by leveraging dbt's templating engine. The project releases in conjunction with the main SQLFluff library, with version 4.1.0 being the latest as of March 2026. [2, 5, 13]","language":"python","status":"active","last_verified":"Fri Apr 10","install":{"commands":["pip install sqlfluff sqlfluff-templater-dbt dbt-core dbt-snowflake # Replace dbt-snowflake with your adapter"],"cli":null},"imports":[],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://www.sqlfluff.com","github":"https://github.com/sqlfluff/sqlfluff","docs":"https://docs.sqlfluff.com","changelog":"https://github.com/sqlfluff/sqlfluff/blob/main/CHANGELOG.md","pypi":"https://pypi.org/project/sqlfluff-templater-dbt/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"# 1. Create a dbt project, e.g., using `dbt init my_dbt_project`\n# 2. Navigate into your dbt project directory\n# 3. Create a .sqlfluff configuration file:\n# .sqlfluff\n# ---\n# [sqlfluff]\n# dialect = snowflake # Or your dbt adapter's dialect\n# templater = dbt\n#\n# [sqlfluff:templater:dbt]\n# project_dir = ./\n# profiles_dir = ~/.dbt/ # Or path to your dbt profiles.yml\n#\n# [sqlfluff:templater:jinja]\n# apply_dbt_builtins = True # Enable dbt macros like `ref`, `var`, `is_incremental()`\n# ---\n\n# 4. Create an optional .sqlfluffignore file to exclude dbt artifacts:\n# .sqlfluffignore\n# ---\n# target/\n# dbt_packages/\n# macros/\n# venv/\n# .venv/\n# node_modules/\n# logs/\n# ---\n\n# 5. Run SQLFluff to lint your dbt project\n# (Make sure your dbt profile is configured for compilation if models query database at compile time)\nimport subprocess\nimport os\n\n# Example dbt model file\nwith open('models/my_model.sql', 'w') as f:\n    f.write(\"-- my_model.sql\\n\\nSELECT {{ ref('another_model') }} FROM {{ source('my_schema', 'my_table') }}\\n\")\n\n# Lint all SQL files in the project\nprint(\"\\n--- Running sqlfluff lint ---\")\nresult_lint = subprocess.run(['sqlfluff', 'lint', '.'], capture_output=True, text=True)\nprint(result_lint.stdout)\nif result_lint.stderr: print(\"Error:\", result_lint.stderr)\n\n# Fix linting issues (if any are auto-fixable)\nprint(\"\\n--- Running sqlfluff fix ---\")\nresult_fix = subprocess.run(['sqlfluff', 'fix', '.'], capture_output=True, text=True)\nprint(result_fix.stdout)\nif result_fix.stderr: print(\"Error:\", result_fix.stderr)","lang":"python","description":"To use sqlfluff-templater-dbt, you must first install the package along with `sqlfluff`, `dbt-core`, and your specific `dbt` adapter. You then configure SQLFluff in a `.sqlfluff` file at your dbt project root, explicitly setting `templater = dbt` and specifying your SQL `dialect`. [1, 4, 12] It's also recommended to configure `project_dir` and `profiles_dir` within the `[sqlfluff:templater:dbt]` section and enable dbt built-ins in the `[sqlfluff:templater:jinja]` section. [1, 4, 9] An `.sqlfluffignore` file is crucial to prevent linting dbt compilation artifacts. [1, 12] Once configured, you can run `sqlfluff lint` or `sqlfluff fix` from your project's root.","tag":null,"tag_description":null,"last_tested":"2026-04-25","results":[{"runtime":"python:3.10-alpine","exit_code":2},{"runtime":"python:3.10-slim","exit_code":2},{"runtime":"python:3.11-alpine","exit_code":2},{"runtime":"python:3.11-slim","exit_code":2},{"runtime":"python:3.12-alpine","exit_code":2},{"runtime":"python:3.12-slim","exit_code":2},{"runtime":"python:3.13-alpine","exit_code":2},{"runtime":"python:3.13-slim","exit_code":2},{"runtime":"python:3.9-alpine","exit_code":2},{"runtime":"python:3.9-slim","exit_code":2}]},"compatibility":null}