A flake8 plugin that flags Python code which can be rewritten in a simpler form, such as merging isinstance calls or replacing if-blocks with ternaries.
PyCQA/mccabe
A Python tool that computes McCabe cyclomatic complexity for functions and runs as a flake8 plugin to flag overly complex code.
- Stars
- 684
- Forks
- 70
- Open issues
- 12
- Last commit
- 25 days ago
What is it?
mccabe measures the McCabe (cyclomatic) complexity of Python code, a count of the independent execution paths through a function. High scores point to functions that are hard to read and test. The project can be run as a standalone module on a file, printing each function with its complexity above a chosen threshold.
It also works as a plugin for flake8, the Python code checker. Once installed, the plugin is disabled by default and is enabled with the --max-complexity option, which reports a C901 warning for any function whose complexity exceeds the given value.
The project is maintained under the PyCQA organization and supports recent Python 3 versions, with the 0.7.0 release dropping support for Python versions below 3.6.
Key features
- 01Computes McCabe cyclomatic complexity for Python functions and methods.
- 02Runs as a standalone command via python -m mccabe with a --min threshold.
- 03Integrates with flake8 through the --max-complexity option and reports C901 warnings.
- 04Supports async/await syntax and recent Python 3 versions.
Use cases
- Flagging overly complex functions during code review or in continuous integration.
- Enforcing a complexity limit across a Python project through flake8 configuration.
- Finding the most complex functions in a module before refactoring.
Quick start
- 1
Install mccabe from PyPI with pip
pip install mccabe - 2
Run the standalone checker on a Python file to list the most complex functions
python -m mccabe --min 5 mccabe.py - 3
Use it as a flake8 plugin by setting a maximum complexity
flake8 --max-complexity 10 coolproject
Things to know
- The license is not clearly declared in the project metadata, so check the license file before commercial use.
- Plugin checks are disabled by default and must be enabled with --max-complexity.
In collections
Topics
FAQ
- What is mccabe?
- A Python tool that computes McCabe cyclomatic complexity for functions and runs as a flake8 plugin to flag overly complex code. mccabe measures the McCabe (cyclomatic) complexity of Python code, a count of the independent execution paths through a function. High scores point to functions that are hard to read and test. The project can be run as a standalone module on a file, printing each function with its complexity above a chosen threshold.
- Is mccabe free to use? What license does it have?
- mccabe is open source under the Other license. Check the license terms before using it in commercial products.
- Is mccabe still maintained?
- Actively maintained. The last commit to mccabe was on Oct 12, 2026.
- What can I use mccabe for?
- Flagging overly complex functions during code review or in continuous integration. Enforcing a complexity limit across a Python project through flake8 configuration. Finding the most complex functions in a module before refactoring.
- How do I install mccabe?
- Install mccabe from PyPI with pip: pip install mccabe Run the standalone checker on a Python file to list the most complex functions: python -m mccabe --min 5 mccabe.py Use it as a flake8 plugin by setting a maximum complexity: flake8 --max-complexity 10 coolproject
- Where can I get mccabe?
- The source code and installation instructions are on GitHub: https://github.com/PyCQA/mccabe
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Python linter that wraps PyFlakes, pycodestyle and McCabe into one command, with support for third-party plugins.
A strict, opinionated flake8 plugin that enforces consistent, simple Python code style and flags complex code patterns.
A flake8 and Pylama plugin that checks whether Python imports are grouped and ordered according to a chosen style guide.
A single-file Python checker that tests code against the style conventions of PEP 8, using only the standard library.
A Flake8 plugin that flags likely bugs and questionable design patterns that pyflakes and pycodestyle don't check.