🌐
Python
peps.python.org › pep-0008
PEP 8 – Style Guide for Python Code | peps.python.org
This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.
🌐
Pep8
pep8.org
PEP 8: The Style Guide for Python Code
This document gives coding conventions for the Python code comprising the standard library in the main Python distribution.
🌐
PyPI
pypi.org › project › pep8
pep8 · PyPI
Small: Just one Python file, requires only stdlib. You can use just the pep8.py file for this purpose.
      » pip install pep8
    
Published   Oct 24, 2017
Version   1.7.1
🌐
Code Beautify
codebeautify.org › python-formatter-beautifier
Python Formatter and Beautifier
Python Beautifier Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.
🌐
Pyrfecter
pyrfecter.com › format-python-code
Format Python code online · Pyrfecter
June 26, 2025 - autopep8 formats Python code according to PEP 8 - Style Guide for Python Code. It builds on top of pycodestyle (formerly known as "pep8") by automatically fixing issues that pycodestyle finds.
🌐
Real Python
realpython.com › python-pep8
How to Write Beautiful Python Code With PEP 8 – Real Python
January 12, 2025 - ... How to use linters and autoformatters to check your code against PEP 8 guidelines and apply some of them automatically · If you want to learn more about PEP 8, then you can read the full documentation or visit pep8.org, which contains the ...
🌐
Codewof
codewof.co.nz › style › python3
Python 3 Style Checker for beginners - codeWOF
This style checker will check your code against the main conventions recommended for Python in PEP 8 (Style Guide for Python Code) and PEP 257 (Docstring Conventions). Fine tuning your code to pass these common conventions makes it easy for others to read your Python code · Privacy notice: ...
🌐
Python
python.org › dev › peps › pep-0008
PEP 8 -- Style Guide for Python Code | Python.org
March 3, 2022 - The official home of the Python Programming Language
🌐
PyPI
pypi.org › project › autopep8
autopep8
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Find elsewhere
🌐
GitHub
github.com › PyCQA › pycodestyle
GitHub - PyCQA/pycodestyle: Simple Python style checker in one Python file · GitHub
$ pycodestyle --show-source --show-pep8 testing/data/E40.py testing/data/E40.py:2:10: E401 multiple imports on one line import os, sys ^ Imports should usually be on separate lines. Okay: import os\nimport sys E401: import sys, os · Or you can display how often each error was found: $ pycodestyle --statistics -qq Python-2.5/Lib 232 E201 whitespace after '[' 599 E202 whitespace before ')' 631 E203 whitespace before ',' 842 E211 whitespace before '(' 2531 E221 multiple spaces before operator 4473 E301 expected 1 blank line, found 0 4006 E302 expected 2 blank lines, found 1 165 E303 too many blank lines (4) 325 E401 multiple imports on one line 3615 E501 line too long (82 characters)
Starred by 5.2K users
Forked by 752 users
Languages   Python 99.9% | Makefile 0.1%
🌐
Encode64
encode64.com › home › formatters › python formatter
Free Online Python Formatter – Black & PEP 8 Style Code Beautifier | Encode64
Clean up your Python code in one click with a Black-style formatter. This online tool enforces consistent indentation, spacing and line length so your scripts, APIs and notebooks stay readable, reviewable and PEP 8–friendly.
🌐
GitHub
github.com › treyhunner › pep8
GitHub - treyhunner/pep8: Simple Python style checker in one Python file · GitHub
Simple Python style checker in one Python file. Contribute to treyhunner/pep8 development by creating an account on GitHub.
Starred by 47 users
Forked by 24 users
Languages   Python
🌐
Herokuapp
pep8ci.herokuapp.com
CI Python Linter
CI Python Linter · Settings: · Results: · All clear, no errors found
🌐
Happyformatter
happyformatter.com › home › instant python formatter – private, pep-8 perfect, browser-based
Python pep8 Formatter Online | Free HAPPYFMT Tool
Free online Python formatter and beautifier. Format, validate, and beautify your Python code with PEP 8 compliance. Privacy-focused, client-side processing.
🌐
Hexmos
hexmos.com › freedevtools › c › security › autopep8
Autopep8 - Python Code Formatter for PEP 8 Compliance Cheatsheet | security Reference | Online Free DevTools
# Automatically format a Python file to conform to PEP 8 autopep8 myfile.py # Format a Python file in-place (modifies the file directly) autopep8 --in-place myfile.py # Format all Python files in a directory and subdirectories recursively autopep8 --in-place --recursive my_directory/ # Format a Python file and display the differences only (without changing the file) autopep8 --diff myfile.py # Aggressively apply formatting changes (can be used multiple times for more aggressive changes) autopep8 --aggressive myfile.py autopep8 --aggressive --aggressive myfile.py # Specify a maximum line length
🌐
Formatter.org
formatter.org › python-formatter
Python Formatter Online – Beautify and Format Python Code
Beautify and format Python code online to improve readability, fix indentation, and keep formatting consistent.
🌐
DataCamp
datacamp.com › tutorial › pep8-tutorial-python-code
PEP-8: Python Naming Conventions & Code Standards | DataCamp
April 11, 2023 - On top of the handy pep8 module and the coala package, you can also check whether your Python code is PEP-8 compliant by going to pep8online. This site has an online editor which allows you to just paste in your code, press the "Check code" button! As a result, you'll get some feedback on what ...
Top answer
1 of 6
218

You can use autopep8! Whilst you make yourself a cup of coffee this tool happily removes all those pesky PEP8 violations which don't change the meaning of the code.

Install it via pip:

pip install autopep8

Apply this to a specific file:

autopep8 py_file --in-place

or to your project (recursively), the verbose option gives you some feedback of how it's going:

autopep8 project_dir --recursive --in-place --pep8-passes 2000 --verbose

Note: Sometimes the default of 100 passes isn't enough, I set it to 2000 as it's reasonably high and will catch all but the most troublesome files (it stops passing once it finds no resolvable pep8 infractions)...

At this point I suggest retesting and doing a commit!

If you want "full" PEP8 compliance: one tactic I've used is to run autopep8 as above, then run PEP8, which prints the remaining violations (file, line number, and what):

pep8 project_dir --ignore=E501

and manually change these individually (e.g. E712s - comparison with boolean).

Note: autopep8 offers an --aggressive argument (to ruthlessly "fix" these meaning-changing violations), but beware if you do use aggressive you may have to debug... (e.g. in numpy/pandas True == np.bool_(True) but not True is np.bool_(True)!)

You can check how many violations of each type (before and after):

pep8 --quiet --statistics .

Note: I consider E501s (line too long) are a special case as there will probably be a lot of these in your code and sometimes these are not corrected by autopep8.

As an example, I applied this technique to the pandas code base.

2 of 6
44

Unfortunately "pep8 storming" (the entire project) has several negative side-effects:

  • lots of merge-conflicts
  • break git blame
  • make code review difficult

As an alternative (and thanks to @y-p for the idea), I wrote a small package which autopep8s only those lines which you have been working on since the last commit/branch:

Basically leaving the project a little better than you found it:

pip install pep8radius

Suppose you've done your work off of master and are ready to commit:

# be somewhere in your project directory
# see the diff with pep, see the changes you've made since master
pep8radius master --diff
# make those changes
pep8radius master --diff --in-place

Or to clean the new lines you've commited since the last commit:

pep8radius --diff
pep8radius --diff --in-place

# the lines which changed since a specific commit `git diff 98f51f`
pep8radius 98f51f --diff

Basically pep8radius is applying autopep8 to lines in the output of git/hg diff (from the last shared commit).

This script currently works with git and hg, if your using something else and want this to work please post a comment/issue/PR!