skillfed

complexipy

An extremely fast Python library to calculate the cognitive complexity of Python files, written in Rust.

complexipy v7.0.1 610.3K downloads/30d#5,767 on PyPI761
Permissive license MIT Active released

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 complexipy

uv

uv add complexipy

poetry

poetry add complexipy

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Software Development :: Quality AssuranceTopic :: Software Development :: Testing

Tags

cognitive complexity analysis pythoncode readability metricspython code quality measurementmaintainability scoring toolnesting depth analysishuman comprehension metricsstatic code analysis
code-qualitystatic-analysisci-cd

More Libraries packages