flake8: Python Linter
Flake8 is a Python linting tool that enforces style consistency and checks for programming errors. It combines multiple code quality tools into a single interface: PyFlakes for logical errors, pycodestyle for style checking, and mccabe for code complexity checking.
When to Use Flake8
Flake8 fits established codebases that already run it in CI and have tuned a stable configuration across setup.cfg, tox.ini, or .flake8. Teams that rely on its plugin ecosystem, or want the combined PyFlakes, pycodestyle, and mccabe checks without a migration, get a familiar tool that has been the default Python linter for over a decade.
For new projects, Ruff implements flake8’s rule set (plus many popular plugins) with autofix support and faster runs. See How do Ruff and Pylint compare? for an evaluation of the modern alternatives.
Key Features
Code Analysis
- Detects undefined variables and imports
- Identifies unused imports and variables
- Finds syntax errors and questionable coding patterns
- Measures cyclomatic complexity
Style Enforcement
- Validates PEP 8 compliance
- Checks line length limits
- Enforces whitespace rules
- Verifies import ordering
Configuration Support
- Per-project settings via
setup.cfg,tox.ini, or.flake8 - Line-level error suppression with
# noqa - Granular rule enabling/disabling
- Custom maximum line length
Usage
Basic command line usage:
# Install with uv
uv pip install flake8
# Run flake8
flake8 path/to/code/Limitations
- No auto-fix capabilities
- Slower performance compared ruff
- Limited type checking support
- No formatting capabilities