An extremely fast Python library to calculate the cognitive complexity of Python files, written in Rust.
Actively maintained. Last release 2 weeks ago, commits in 23 of the last 26 weeks. A safe choice.
pip install complexipycomplexipy
Blazingly fast cognitive complexity analysis for Python, written in Rust.
Installation • Quick Start • Features • Integrations • Learn More • Documentation • Changelog • Complexipy Teams
Scoring cognitive complexity of the Django codebase (2,929 files). Benchmarks
Installation
uv tool install complexipy
# or
uv add complexipy
# or
pip install complexipy
The --diff, --diff-only, and --staged options require Git 2.30 or newer
on your PATH. Check your version with git --version. Git is not required
for analysis without these options.
What is Cognitive Complexity?
Cognitive complexity measures how hard a function's control flow is to follow. Use it to keep code easy to review and change, whether a person or an AI agent wrote it.
These two functions have the same cyclomatic complexity, 4. Their cognitive complexity is different:
# Cognitive complexity: 3
def example1(a, b, c):
if a: # +1
return 1
if b: # +1
return 2
if c: # +1
return 3
return 4