A Python tool that computes McCabe cyclomatic complexity for functions and runs as a flake8 plugin to flag overly complex code.
MartinThoma/flake8-simplify
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.
- Stars
- 195
- Forks
- 22
- Open issues
- 59
- Last commit
- 6 days ago
What is it?
flake8-simplify is a plugin for flake8, the Python linter. It adds rules that point out code patterns which have a shorter or more idiomatic equivalent, such as nested if-statements that can be merged, try/except/pass blocks that could use contextlib.suppress, and manual loop counters that could use enumerate.
Each rule reports a code like SIM101 or SIM108 with a location and message, so it fits into the same workflow as other flake8 checks. Rules are enabled simply by installing the package and running flake8, and individual codes can be ignored through the standard flake8 configuration. Newer rules are published under an experimental SIM9 prefix for a trial period before receiving a stable code.
The package supports Python 3.10 through 3.14 and is installed with pip. Some rules that were previously included have been moved to a separate project, flake8-scream.
Key features
- 01Detects nested if-statements that can be merged into one.
- 02Suggests ternary operators, any(), all(), and dict.get() in place of verbose code.
- 03Flags try/except/pass blocks that could use contextlib.suppress.
- 04Reports manual index counters that could be replaced by enumerate.
- 05Runs as a standard flake8 plugin with per-rule ignore settings.
Use cases
- Cleaning up a Python codebase during code review or refactoring.
- Enforcing simpler coding patterns in a team's flake8 setup.
- Learning idiomatic Python by seeing which verbose patterns have shorter equivalents.
Quick start
- 1
Install the plugin with pip
pip install flake8-simplify - 2
Run flake8 on your project to see simplification hints
flake8 .
Things to know
- Experimental SIM9xx rules may change or be renamed after their trial periods.
In collections
Topics
FAQ
- What is flake8-simplify?
- 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. flake8-simplify is a plugin for flake8, the Python linter. It adds rules that point out code patterns which have a shorter or more idiomatic equivalent, such as nested if-statements that can be merged, try/except/pass blocks that could use contextlib.suppress, and manual loop counters that could use enumerate.
- Is flake8-simplify free to use? What license does it have?
- flake8-simplify is open source under the MIT license. Check the license terms before using it in commercial products.
- Is flake8-simplify still maintained?
- Actively maintained. The last commit to flake8-simplify was on Nov 1, 2026.
- What can I use flake8-simplify for?
- Cleaning up a Python codebase during code review or refactoring. Enforcing simpler coding patterns in a team's flake8 setup. Learning idiomatic Python by seeing which verbose patterns have shorter equivalents.
- How do I install flake8-simplify?
- Install the plugin with pip: pip install flake8-simplify Run flake8 on your project to see simplification hints: flake8 .
- Where can I get flake8-simplify?
- The source code and installation instructions are on GitHub: https://github.com/MartinThoma/flake8-simplify
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A strict, opinionated flake8 plugin that enforces consistent, simple Python code style and flags complex code patterns.
A Python linter that wraps PyFlakes, pycodestyle and McCabe into one command, with support for third-party plugins.
A flake8 and Pylama plugin that checks whether Python imports are grouped and ordered according to a chosen style guide.
Command-line tool and flake8 plugin that enforces shared config settings across multiple projects, and can fix config files automatically.
An extremely fast Python linter and code formatter written in Rust, with over 900 lint rules and Black-compatible formatting.