What is PEP 8?
PEP 8 is a Python Enhancement Proposal that defines the style guide for the Python standard library, written by Guido van Rossum in 2001. Technically scoped to the standard library, it became the basis for code style conventions across the ecosystem.
Naming Conventions
snake_casefor functions and variablesPascalCasefor classesUPPERCASEfor constants
Whitespace Rules
- 4 spaces for indentation (no tabs)
- Two blank lines between top-level functions and classes
- One blank line between methods in a class
Line Length
PEP 8 sets a maximum of 79 characters for code and 72 for docstrings and comments. That limit reflects the 80-column terminal standard of the early 2000s. Modern formatters like Ruff and Black default to 88 characters, a pragmatic adjustment that has become the community norm.
Enforcing PEP 8
Flake8 was the dominant PEP 8 linter for over a decade. Most projects have moved to Ruff, which handles both linting (catching PEP 8 violations via its pycodestyle rules) and formatting in a single tool, running faster than Flake8. See How to configure recommended Ruff defaults for setup, or How to replace Black, isort, Flake8, and pyupgrade with Ruff to consolidate an existing linting stack.
Learn More
- PEP 8 covers indentation, naming, line length, and the rationale behind each rule
- What is a PEP?