Generated by GPT-5-mini| PEP 8 | |
|---|---|
| Name | PEP 8 |
| Subject | Style guide for Python code |
| Author | Guido van Rossum, Barry Warsaw, Nick Coghlan |
| Released | 2001 |
| Status | Active |
PEP 8
PEP 8 is the style guide that prescribes conventions for writing Python source code, aiming to improve readability and consistency across projects. It complements the Python language specification and ecosystem practices established by figures like Guido van Rossum, organizations like the Python Software Foundation, projects such as CPython, and events like PyCon. The guide has influenced tooling in editors and linters developed by contributors from communities including GitHub, Mozilla, Google, and Microsoft.
PEP 8 originated in 2001 when several core developers sought uniform conventions for the growing CPython codebase, influenced by earlier style efforts in projects like GNU Project and practices at companies such as Zope Corporation. Key contributors included Guido van Rossum, Barry Warsaw, and Nick Coghlan, who incorporated feedback from mailing lists and repositories hosted on platforms like SourceForge and later GitHub. Over time, updates reflected changes in language features introduced in releases like Python 2.4, Python 3.0, and later maintenance for compatibility with developments in PEP 257 and the Python Enhancement Proposal process itself. Adoption expanded through toolchains created by organizations such as JetBrains and projects like flake8, pylint, and black, which automated enforcement across corporate codebases at Google, Facebook, and Instagram.
PEP 8 prescribes a set of core rules addressing naming, layout, and programming idioms. Names should follow conventions adopted by libraries in CPython and standards used by teams at Dropbox and Red Hat; examples include lower_case_with_underscores for functions and MixedCase for classes. Indentation and line length guidance reflect practices from editors by Emacs and Vim and align with print constraints historically used at publishers like O'Reilly Media. Style rules touch on imports ordering a la PEP 328, whitespace around operators, and the use of docstrings consistent with PEP 257 and documentation tools such as Sphinx.
This section groups conventions commonly applied in open source and corporate projects like Django, Flask, NumPy, Pandas, and TensorFlow.
- Naming: Classes follow conventions seen in CPython and frameworks like Tornado (web server), while constants mirror practices from libraries at Mozilla and Redis. - Layout: Line length and wrapping guidance mirror editorial traditions from publishers like Addison-Wesley and code-wrapping strategies used by teams at Google and Microsoft. - Imports: Ordering and grouping practices evolved alongside proposals implemented in PEP 328 and tools used by pip and setuptools communities. - Whitespace: Recommendations reflect formatting decisions adopted in large projects such as OpenStack and Kubernetes client libraries. - Comments and Docstrings: Conventions align with documentation standards in Sphinx and examples from the Python Standard Library as curated by contributors from the Python Software Foundation. - Programming Recommendations: Idiomatic patterns encouraged in PEP 8 are visible in scientific ecosystems like SciPy and Matplotlib, and in data projects at Netflix and Airbnb.
The principles behind the guide emphasize readability, consistency, and maintainability, goals shared with projects like UNIX toolchains and standards bodies such as IETF. PEP 8’s prescriptions are pragmatic compromises influenced by code review cultures at institutions including MIT, Stanford University, and companies like Google. The design privileges minimal ceremony to facilitate collaboration across distributed teams using platforms like GitHub and GitLab, and to integrate with continuous integration systems developed by Travis CI and Jenkins.
PEP 8 has been adopted widely in open source ecosystems exemplified by Django, Flask, Pandas, and NumPy, and within enterprises including Google, Microsoft, and Facebook. It shaped the development of style checkers and formatters such as flake8, pylint, black, and autopep8, which are integrated into editors from JetBrains and extensions for Visual Studio Code and automated pipelines on services like CircleCI. The guide’s influence extends to academic codebases at institutions like Harvard University and Caltech, and to documentation standards used in technical publishing by O'Reilly Media.
Critiques of the guide include debates over specific limits (such as line length), rigidity versus flexibility in projects like Django and Flask, and disagreements about automated formatting exemplified by reactions to tools like black. Some organizations and developers argue for contextual adaptation as practiced at Google and Facebook, while others advocate strict enforcement as in the CPython core team workflow. Further controversies arise when style enforcement intersects with legacy codebases maintained by institutions like NASA and companies such as Oracle, prompting discussions in forums including Stack Overflow and mailing lists hosted on Mailman.