Skip to main content

SQLFluff plugin for SQL and dbt model complexity rules

Project description

sqlfluff-complexity

SQLFluff rules and reports for finding SQL and dbt models that are too complex to review safely.

sqlfluff-complexity adds CPX rules to SQLFluff for CTE count, join count, nested subquery depth, CASE expressions, nested CASE depth, boolean predicates, window functions, CTE dependency depth, set operations (UNION / INTERSECT / EXCEPT), inline derived tables, and an aggregate weighted complexity score. The same metric engine also powers a companion sqlfluff-complexity report command for non-blocking console, JSON, SARIF, and standalone HTML reports.

Who It Is For

  • Analytics engineers who want dbt models to stay small enough to review.
  • Data platform teams that already run SQLFluff in local development or CI.
  • Teams that want gradual complexity reporting before turning on strict lint failures.

Quick Start

Requires SQLFluff 4.x in the same environment (sqlfluff>=4,<5). SQLFluff 3 is not supported as of sqlfluff-complexity 0.4.0; pin sqlfluff-complexity<0.4 if you cannot upgrade SQLFluff yet.

Install the custom SQLFluff plugin in the same Python environment where you run SQLFluff:

pip install sqlfluff-complexity

If your project uses uv:

uv add --dev sqlfluff-complexity

Then enable CPX rules in .sqlfluff and run SQLFluff:

[sqlfluff]
dialect = postgres
rules = CPX_C101,CPX_C102,CPX_C103,CPX_C104,CPX_C105,CPX_C106,CPX_C107,CPX_C108,CPX_C109,CPX_C110,CPX_C201
sqlfluff lint models/

For a complete walkthrough, see docs/quickstart.md.

Migrating complexity_weights: Use a JSON object in [sqlfluff:rules:CPX_C201] (not comma-separated key:value lists). See Configuration: aggregate score and CHANGELOG.

Documentation

Large dbt projects

This plugin does not read dbt artifacts (manifest.json, run_results.json, catalog.json) or graph metadata. Complexity is measured from the SQLFluff parse tree only—which aligns well with SQLFluff’s dbt templater so ref(), source(), and macros compile before linting.

Practical adoption patterns:

  • Use the dbt templater when you need compiled SQL fidelity; keep sqlfluff-complexity focused on structural signals from parsed SQL.
  • Tune thresholds per rule and use path_overrides on CPX_C201 where staging vs marts need different budgets.
  • Prefer sqlfluff lint on changed models in CI and sqlfluff-complexity report for broader visibility without failing builds.
  • For CTE dependency depth, see docs/rules.md (CPX_C107) and docs/reporting.md (report vs per-WITH lint).

See also dbt usage and configuration.

Project Status

  • Native SQLFluff plugin rules and the companion report CLI are available in the package.
  • v1 measures SQLFluff-parsed SQL; direct dbt manifest.json and DAG-level metrics are deferred.
  • Architecture decisions are recorded in docs/adr/.

Development

Contributor setup, Nox sessions, fixture authoring, ADR workflow, and verifier guidance live in CONTRIBUTING.md. Agent-specific project instructions live in AGENTS.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlfluff_complexity-0.5.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlfluff_complexity-0.5.0-py3-none-any.whl (73.5 kB view details)

Uploaded Python 3

File details

Details for the file sqlfluff_complexity-0.5.0.tar.gz.

File metadata

  • Download URL: sqlfluff_complexity-0.5.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for sqlfluff_complexity-0.5.0.tar.gz
Algorithm Hash digest
SHA256 044ce10a02ea4e258405dccc0a48b56fe662b574c3ae24eaeb7f8a6de09327f4
MD5 ac9e922ce4cf4946bfb919b951a1c581
BLAKE2b-256 693f429d6b396160c8528049ab08f67b5604c74feafc81fd9e6861b01bce0b3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlfluff_complexity-0.5.0.tar.gz:

Publisher: publish.yml on yu-iskw/sqlfluff-complexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlfluff_complexity-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlfluff_complexity-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ae5af9860715ab25dcc0b5736c87fff32345ee02135c2de8aa96cca26f46f91
MD5 fc559108ac0adefa20e31450eedbfb02
BLAKE2b-256 cbe4d095d1435e2cce2a220d16503dc9238194747a80baa72c23eedfef9f1722

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlfluff_complexity-0.5.0-py3-none-any.whl:

Publisher: publish.yml on yu-iskw/sqlfluff-complexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page