Skip to main content

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

  • Quick start: install, configure, and run the first lint.
  • Configuration: thresholds, aggregate weights, SQLFluff nested config by path, and path_overrides.
  • Rules reference: CPX rule codes and what each metric counts.
  • Reporting: console, JSON, SARIF, and HTML report mode.
  • Python API: stable programmatic imports (today: report pipeline and related config helpers; more subcommands documented here as they ship).
  • Adoption: calibration, CI/SARIF examples, before/after SQL vignette.
  • dbt usage: SQLFluff dbt templater compatibility and v1 boundaries.
  • Dialects: tested dialects and dbt adapter mapping caveats.
  • Docs index: all user, contributor, and design documents.
  • Internal import migration: if you import sqlfluff_complexity.core submodules directly, update paths after subpackage refactors.

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.

Metadata

Release files for sqlfluff-complexity 0.5.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlfluff-complexity 0.5.4
File Size Uploaded Provenance
sqlfluff_complexity-0.5.4.tar.gz 3.8 MB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlfluff-complexity 0.5.4
File Interpreter ABI Platform
sqlfluff_complexity-0.5.4-py3-none-any.whl Python 3 none any Details

Total release size: 3.9 MB

Release files / sqlfluff_complexity-0.5.4.tar.gz

Download URL sqlfluff_complexity-0.5.4.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
ba5ee539b09ad605b34b814d4b67d0dcc7b0e362e9db929b827addde1b474ce9
BLAKE2b-256 checksum
How to use checksums
7c315b0b40e3e91d9f618dd6254b3d5874adaae8a6314817955e226d7fbc42de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

Release files / sqlfluff_complexity-0.5.4-py3-none-any.whl

Download URL sqlfluff_complexity-0.5.4-py3-none-any.whl
Size 75.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b937564936599fdbe505149e52fbb3ffaeb3a7c974055825ab4ad3f6b8a14c1
BLAKE2b-256 checksum
How to use checksums
b17cf7d0f1b8384a703e5e603173e20ef01c9954c5863585931af38792735172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

Security for sqlfluff-complexity 0.5.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sqlfluff_complexity-0.5.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page