Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 5, 2026·3 min de lecture

Flake8 — The Python Linting Tool That Wraps pycodestyle, pyflakes & McCabe

A command-line tool that checks Python code against PEP 8 style conventions, detects logical errors, and measures cyclomatic complexity. Extensible through hundreds of community plugins.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Flake8
Commande d'installation directe
npx -y tokrepo@latest install 4fe1f048-782c-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Flake8 is one of the most widely used Python linting tools. It combines three core checkers — pycodestyle for PEP 8 style, pyflakes for logical errors, and mccabe for complexity — into a single unified command, and supports hundreds of third-party plugins for additional checks.

What Flake8 Does

  • Checks Python source code against PEP 8 style guidelines including indentation, whitespace, and naming
  • Detects logical errors like unused imports, undefined names, and unreachable code via pyflakes
  • Measures cyclomatic complexity of functions and flags those exceeding a configurable threshold
  • Reports violations with file, line, column, and error code for easy integration with editors and CI
  • Supports inline noqa comments to selectively suppress warnings on a per-line basis

Architecture Overview

Flake8 acts as a wrapper that runs pycodestyle, pyflakes, and mccabe against each source file and aggregates results into a unified report. Its plugin architecture uses Python entry points: any package that registers a checker under the flake8.extension group is automatically discovered and invoked during linting. Configuration is read from setup.cfg, tox.ini, or .flake8 files, with command-line flags taking precedence.

Self-Hosting & Configuration

  • Install via pip into your project's virtual environment or globally
  • Configure project-wide settings in a .flake8, setup.cfg, or tox.ini file under the [flake8] section
  • Set max-line-length, exclude patterns, and per-file-ignores to match your team's standards
  • Install plugins like flake8-bugbear, flake8-docstrings, or flake8-import-order for extended checks
  • Add Flake8 to your CI pipeline or pre-commit hooks for automated enforcement

Key Features

  • Unified interface for style, error, and complexity checking in a single command
  • Plugin ecosystem with hundreds of third-party checkers available on PyPI
  • Per-file-ignores allow different rules for tests, migrations, and generated code
  • Inline # noqa comments provide fine-grained suppression with optional error codes
  • Deterministic output format integrates with editors, CI systems, and code review tools

Comparison with Similar Tools

  • Ruff — a Rust-based Python linter that is significantly faster and implements most Flake8 rules natively; Flake8 has a larger plugin ecosystem
  • Pylint — a more comprehensive static analyzer with type inference and refactoring suggestions; Flake8 is faster and focused on style and common errors
  • pycodestyle — the standalone PEP 8 checker that Flake8 wraps; Flake8 adds logical error detection and plugin support
  • Black — an opinionated code formatter that fixes style issues automatically; Flake8 reports issues but does not modify code

FAQ

Q: How does Flake8 differ from Ruff? A: Ruff reimplements most Flake8 rules in Rust for dramatically faster execution. Flake8 remains relevant for teams that depend on specific Flake8 plugins not yet available in Ruff.

Q: Can I use Flake8 alongside Black? A: Yes. Configure Flake8 with max-line-length = 88 and extend-ignore = E203 to match Black's formatting decisions and avoid conflicts.

Q: How do I suppress a specific warning? A: Add # noqa: E501 (or the relevant error code) at the end of the line, or use per-file-ignores in your config file for broader suppression.

Q: Does Flake8 check type annotations? A: Flake8 does not perform type checking itself, but plugins like flake8-annotations can enforce annotation presence and style.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires