flake8: Style Linting Command Reference
The long-standing pyflakes + pycodestyle linter.
flake8 combines pyflakes and pycodestyle to catch unused imports, undefined names, and style violations. It remains a common CI lint gate, though ruff is a faster alternative.
Common flags / usage
- flake8 . -- lint the current tree
- --select CODES -- enable only specific checks
- --extend-ignore CODES -- ignore additional checks
- --max-line-length N -- set the line-length limit
- config via setup.cfg, tox.ini, or .flake8
Example
shell
- run: pip install flake8
- run: flake8 --max-line-length=100 src/ tests/In CI
Keep flake8 settings in setup.cfg or .flake8 so local and CI runs agree. flake8 exits non-zero on any finding, gating the build. Many teams now run ruff check for the same coverage at much higher speed.
Key takeaways
- flake8 catches style issues and simple errors via pyflakes/pycodestyle.
- Configure it in setup.cfg/.flake8 so CI and local match.
- It gates on any finding; ruff is a faster modern alternative.
Related guides
ruff check: Fast Linting Command ReferenceReference for ruff check in CI: fast Python linting, the --fix and --output-format flags, gating on lint erro…
black --check: Formatting Gate Command ReferenceReference for black --check in CI: verifying formatting without rewriting files, the --diff flag, exit codes…
mypy: Static Type Checking Command ReferenceReference for mypy in CI: static type checking, strict mode, caching for speed, handling missing stubs, and a…