rohaquinlop/complexipy

Blazingly fast cognitive complexity analysis for Python, written in Rust.

Rust

891

888 commits

updated Oct 19, 2026

See the code

README

complexipy

complexipy

Blazingly fast cognitive complexity analysis for Python, written in Rust.

PyPI Downloads License

Installation • Quick Start • Integrations • Learn More • Documentation • Changelog • Complexipy Teams

What is Cognitive Complexity?

Cognitive complexity measures how hard code is to understand by humans, not machines.

Unlike traditional metrics like cyclomatic complexity, cognitive complexity accounts for nesting depth and control flow patterns that affect human comprehension. Inspired by G. Ann Campbell's research at SonarSource, complexipy provides a fast, accurate implementation for Python.

Key benefits:

  • Human-focused - Penalizes nesting, flow breaks, and human-unfriendly logic
  • Actionable insights - Identifies genuinely hard-to-maintain code
  • Different from cyclomatic - Measures readability while cyclomatic measures structural, testing, and branch density

Common Questions

How is complexity calculated? Learn about the scoring algorithm, what each control structure contributes, and how nesting affects the final score.

How does this compare to Ruff's PLR0912? Understand the key differences between cyclomatic complexity (Ruff) and cognitive complexity (complexipy), and why you might want to use both.

Is this a SonarSource/Sonar product? No. complexipy is an independent project inspired by G. Ann Campbell's research, but it's not affiliated with or endorsed by SonarSource.

Installation

pip install complexipy
# or
uv add complexipy

Quick Start

Command Line

# Analyze the current directory
complexipy .

# Set a custom threshold
complexipy . --max-complexity-allowed 10

# Show failing functions with refactor suggestions
complexipy . --failed --suggest-refactors

# Save results to JSON
complexipy . --output-format json

# Block regressions against a git reference
complexipy . --diff main

# Exclude paths with glob patterns
complexipy . --exclude "tests/**"

Python API

from complexipy import file_complexity

# Analyze a file
result = file_complexity("app.py", check_script=True)
print(f"File complexity: {result.complexity}")

for func in result.functions:
    print(f"{func.name}: {func.complexity}")

Integrations

🔧 GitHub Actions
- uses: rohaquinlop/complexipy-action@v2
  with:
      paths: .
      max_complexity_allowed: 10
      output_format: json
🪝 Pre-commit Hook
repos:
    - repo: https://github.com/rohaquinlop/complexipy-pre-commit
      rev: v5.1.0
      hooks:
          - id: complexipy
🔌 VS Code Extension

Install from the marketplace It runs the complexipy language server, so install complexipy too (uv tool install complexipy). Inlay hints, hover, and warnings update as you type.

🧩 Editor Integration

Every editor uses complexipy lsp, a language server with inlay hints, hover, and warnings. See Editor Integration for the VS Code, Neovim, and Zed setup.

Learn More


Inspired by the Cognitive Complexity research by G. Ann Campbell
complexipy is an independent project and is not affiliated with or endorsed by SonarSource

Documentation • PyPI • GitHub

Built with ❤️ by @rohaquinlop and contributors

clean-code
code-quality
cognitive-complexity
cognitive-load
maintainability
quality
quality-control
understandability

rohaquinlop/complexipy

Blazingly fast cognitive complexity analysis for Python, written in Rust.

Rust

891

888 commits

updated Oct 19, 2026

See the code

README

complexipy

complexipy

Blazingly fast cognitive complexity analysis for Python, written in Rust.

PyPI Downloads License

Installation • Quick Start • Integrations • Learn More • Documentation • Changelog • Complexipy Teams

What is Cognitive Complexity?

Cognitive complexity measures how hard code is to understand by humans, not machines.

Unlike traditional metrics like cyclomatic complexity, cognitive complexity accounts for nesting depth and control flow patterns that affect human comprehension. Inspired by G. Ann Campbell's research at SonarSource, complexipy provides a fast, accurate implementation for Python.

Key benefits:

  • Human-focused - Penalizes nesting, flow breaks, and human-unfriendly logic
  • Actionable insights - Identifies genuinely hard-to-maintain code
  • Different from cyclomatic - Measures readability while cyclomatic measures structural, testing, and branch density

Common Questions

How is complexity calculated? Learn about the scoring algorithm, what each control structure contributes, and how nesting affects the final score.

How does this compare to Ruff's PLR0912? Understand the key differences between cyclomatic complexity (Ruff) and cognitive complexity (complexipy), and why you might want to use both.

Is this a SonarSource/Sonar product? No. complexipy is an independent project inspired by G. Ann Campbell's research, but it's not affiliated with or endorsed by SonarSource.

Installation

pip install complexipy
# or
uv add complexipy

Quick Start

Command Line

# Analyze the current directory
complexipy .

# Set a custom threshold
complexipy . --max-complexity-allowed 10

# Show failing functions with refactor suggestions
complexipy . --failed --suggest-refactors

# Save results to JSON
complexipy . --output-format json

# Block regressions against a git reference
complexipy . --diff main

# Exclude paths with glob patterns
complexipy . --exclude "tests/**"

Python API

from complexipy import file_complexity

# Analyze a file
result = file_complexity("app.py", check_script=True)
print(f"File complexity: {result.complexity}")

for func in result.functions:
    print(f"{func.name}: {func.complexity}")

Integrations

🔧 GitHub Actions
- uses: rohaquinlop/complexipy-action@v2
  with:
      paths: .
      max_complexity_allowed: 10
      output_format: json
🪝 Pre-commit Hook
repos:
    - repo: https://github.com/rohaquinlop/complexipy-pre-commit
      rev: v5.1.0
      hooks:
          - id: complexipy
🔌 VS Code Extension

Install from the marketplace It runs the complexipy language server, so install complexipy too (uv tool install complexipy). Inlay hints, hover, and warnings update as you type.

🧩 Editor Integration

Every editor uses complexipy lsp, a language server with inlay hints, hover, and warnings. See Editor Integration for the VS Code, Neovim, and Zed setup.

Learn More


Inspired by the Cognitive Complexity research by G. Ann Campbell
complexipy is an independent project and is not affiliated with or endorsed by SonarSource

Documentation • PyPI • GitHub

Built with ❤️ by @rohaquinlop and contributors

clean-code
code-quality
cognitive-complexity
cognitive-load
maintainability
quality
quality-control
understandability

Project health

Latest release

8.0.1 · Sep 7, 2026

Releases this year

17

Significant stargazers

Carol Willing

1,566 followers · starred Apr 2026

Timothée Mazzucotelli

625 followers · starred Oct 2024

Yuta Hayashibe

114 followers · starred Nov 2025

Axel H.

289 followers · starred Oct 2024