complexipy
An extremely fast Python library to calculate the cognitive complexity of Python files, written in Rust.
What it is and what it does
complexipy is a Python library that measures cognitive complexity—how hard code is to understand for humans—by analyzing nesting depth, control flow patterns, and code structure. Unlike cyclomatic complexity, which counts branches, cognitive complexity penalizes nested logic and human-unfriendly patterns to reflect actual readability challenges. The library is written in Rust for speed and provides both a command-line tool and a Python API.
You can use it to analyze individual files or entire codebases, set complexity thresholds, generate reports in multiple formats (JSON, CSV, SARIF, GitLab), compare complexity across git references, and integrate into CI/CD pipelines. It supports configuration via TOML files and includes pre-commit hooks, GitHub Actions, and VS Code integration.
Use it for:
- Enforce code quality standards in CI/CD by failing builds when functions exceed a complexity threshold
- Identify the most complex functions in a codebase to prioritize refactoring efforts
- Track complexity regressions in pull requests by comparing against a baseline branch
- Generate SARIF reports for GitHub Code Scanning to surface maintainability issues as inline PR annotations
- Integrate with pre-commit hooks to catch overly complex functions before they reach the repository
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Calculates cognitive complexity scores for Python code to measure how hard code is to understand by humans, accounting for nesting depth and control flow patterns.
Yes. complexipy is actively maintained, has no known vulnerabilities, uses a permissive MIT license, and fills a genuine need for cognitive complexity analysis in Python. The Rust backend and broad platform support (wheels for cp310, cp311, multiple architectures) reduce friction. It's suitable for teams wanting to measure and enforce code readability beyond traditional cyclomatic metrics.
Install
complexipy on PyPI
pip
pip install complexipyuv
uv add complexipypoetry
poetry add complexipyInstalling complexipy
Before you install
Medium install friction due to compiled wheels across multiple platforms (cp310, cp311, and various architectures). Active maintenance with recent release (2 days old) and 761 repository stars indicate solid ongoing support.
License in practice
MIT license is permissive; you can use, modify, and distribute complexipy with minimal restrictions, making it suitable for both open-source and commercial projects.
Quickstart
pip install complexipy
from complexipy import file_complexity
result = file_complexity("app.py")
print(f"File complexity: {result.complexity}")
for func in result.functions:
print(f"{func.name}: {func.complexity}")
Verify before relying
- Whether the Rust implementation provides measurable performance gains over pure-Python alternatives in typical workflows
- How cognitive complexity scores correlate with actual maintenance burden or bug rates in practice
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 2 — tomli, typer |
| Maintenance | actively maintained — 2 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 610,329/month — #5,767 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: complexipy-7.0.1-cp310-cp310-macosx_10_12_x86_64.whl; complexipy-7.0.1-cp310-cp310-macosx_11_0_arm64.whl; complexipy-7.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; complexipy-7.0.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; complexipy-7.0.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl; complexipy-7.0.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; complexipy-7.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl; complexipy-7.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; complexipy-7.0.1-cp310-cp310-musllinux_1_2_aarch64.whl; complexipy-7.0.1-cp310-cp310-musllinux_1_2_x86_64.whl; complexipy-7.0.1-cp310-cp310-win32.whl; complexipy-7.0.1-cp310-cp310-win_amd64.whl; complexipy-7.0.1-cp311-cp311-macosx_10_12_x86_64.whl; complexipy-7.0.1-cp311-cp311-macosx_11_0_arm64.whl; complexipy-7.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; complexipy-7.0.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; complexipy-7.0.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl; complexipy-7.0.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; complexipy-7.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl; complexipy-7.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Keywords: maintainability, usability, DevEx tools, cognitive, complexity, cognitive complexity, quality, quality assurance, libraries, performance, static analysis, code quality, technical debt, refactoring, CI/CD, fast
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
cognitive-complexityCalculates cognitive complexity scores for…
permissive · top 15,000 on PyPI
flake8-cognitive-complexityA flake8 extension that checks Python code for…
permissive · top 15,000 on PyPI
lizardLizard analyzes code complexity and detects…
permissive · top 5,000 on PyPI
xenonXenon monitors Python code complexity by…
permissive · top 5,000 on PyPI
mccabeMeasures cyclomatic complexity of Python…
permissive · top 1,000 on PyPI
radonRadon computes code metrics from Python source…
permissive · top 5,000 on PyPI
flake8-annotations-complexityA flake8 plugin that flags type annotations…
permissive · top 15,000 on PyPI
diff-coverCompares test coverage reports against git…
permissive · top 1,000 on PyPI
pixelhogCompares PNG screenshots pixel-by-pixel and…
permissive · top 5,000 on PyPI
refurbRefurb is a static analysis tool that scans…
copyleft · top 15,000 on PyPI