cognitive-complexity
Library to calculate Python functions cognitive complexity via code
Decision gist · record as of 2026-08-14
Yes, if you need cognitive complexity analysis and are comfortable with an unmaintained library. The package is stable, has no dependencies, and works reliably on Python 3.6+. However, consider it a read-only tool: expect no bug fixes, security patches, or feature updates. If active maintenance is critical for your workflow, investigate whether a maintained alternative exists before committing to this version.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.6 or later; input must be an AST node (typically from ast.parse), not raw source code.
- High install friction: no runtime dependencies but marked as abandoned since the last commit on 2022-08-09 with no maintenance or security updates.
License · maintenance · safety
MIT (permissive) — MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
last release 2022-08-09 (1466 days) · last repo commit 2022-08-09 · 47 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 352,807 downloads/mo, #7,308 on PyPI
Alternatives
Verify before relying
import ast
from cognitive_complexity.api import get_cognitive_complexity
funcdef = ast.parse("def f(a):\n return a * f(a - 1)").body[0]
print(get_cognitive_complexity(funcdef)) # Output: 1- How closely the implementation matches G. Ann Campbell's original algorithm and whether deviations affect reliability for production linting.
- Whether the package is maintained under a different repository or if a maintained fork exists as a drop-in replacement.
- Current stability and compatibility with Python versions beyond 3.8 given the abandoned maintenance status.
What it is and what it does
Cognitive-complexity is a Python library that computes a numeric score representing how cognitively difficult a function is to understand. It works by parsing Python source code into an abstract syntax tree and applying heuristics that award complexity points for control-flow breaks, nesting depth, recursion, and logical operations. The library itself has no runtime dependencies and is typically used either as a standalone API or integrated into flake8 via the flake8-cognitive-complexity extension.
The package is based on research into cognitive complexity as a measure of code understandability—distinct from traditional cyclomatic complexity. The implementation is acknowledged to be an approximation rather than a precise realization of the original algorithm. The project has been abandoned and receives no active maintenance, though it remains functional for Python 3.6+ codebases.
Use it for
- Integrate into a CI/CD pipeline to flag functions exceeding a complexity threshold and enforce code review for high-complexity changes.
- Use as a flake8 plugin to get real-time warnings during development when functions become too difficult to understand.
- Analyze legacy codebases to identify which functions are candidates for refactoring based on cognitive load.
- Build custom linting rules that combine cognitive complexity with other metrics to guide architectural decisions.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need cognitive complexity analysis and are comfortable with an unmaintained library.
The package is stable, has no dependencies, and works reliably on Python 3.6+. However, consider it a read-only tool: expect no bug fixes, security patches, or feature updates. If active maintenance is critical for your workflow, investigate whether a maintained alternative exists before committing to this version.
Install
cognitive-complexity on PyPI
Before you install
High install friction: no runtime dependencies but marked as abandoned since the last commit on 2022-08-09 with no maintenance or security updates.
Requires Python 3.6 or later; input must be an AST node (typically from ast.parse), not raw source code.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
import ast
from cognitive_complexity.api import get_cognitive_complexity
funcdef = ast.parse("def f(a):\n return a * f(a - 1)").body[0]
print(get_cognitive_complexity(funcdef)) # Output: 1
Verify before relying
- How closely the implementation matches G. Ann Campbell's original algorithm and whether deviations affect reliability for production linting.
- Whether the package is maintained under a different repository or if a maintained fork exists as a drop-in replacement.
- Current stability and compatibility with Python versions beyond 3.8 given the abandoned maintenance status.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | High. Source build required |
| Runtime dependencies | None |
| Maintenance | Abandoned 1,466 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 352,807 / month, #7,308 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Environment :: ConsoleOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: Software Development :: DocumentationTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Quality Assurance |
Evidence: cognitive_complexity-1.3.0.tar.gz
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “cognitive complexity measurement”
- cognitive-complexityCalculates cognitive complexity scores for Python functions by…
- complexipyCalculates cognitive complexity scores for Python code to measure how…
- flake8-cognitive-complexityA flake8 extension that checks Python code for cognitive complexity,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also complexipy · flake8-cognitive-complexity · flake8-annotations-complexity · mccabe · flake8-expression-complexity · lizard · radon · flake8-functions · flake8 · wemake-python-styleguide