Format Python code according to the PEP 8 style guide.


Format a file to stdout, with a custom maximum line length

$ autopep8 [path/to/] --max-line-length [length]

Format a file, displaying a diff of the changes
$ autopep8 --diff [path/to/file]

Format a file in-place and save the changes
$ autopep8 --in-place [path/to/]

Recursively format all files in a directory in-place and save changes
$ autopep8 --in-place --recursive [path/to/directory]


usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]

[--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] [--line-range line line] [--hang-closing] [--exit-code] [files ...]

Automatically formats Python code to conform to the PEP 8 style guide.

positional arguments:


files to format or '-' for standard in

optional arguments:

-h, --help

show this help message and exit


show program's version number and exit

-v, --verbose

print verbose messages; multiple -v result in more verbose messages

-d, --diff

print the diff for the fixed source

-i, --in-place

make changes to files in place

--global-config filename

path to a global pep8 config file; if this file does not exist then this is ignored (default: ~/.config)


don't look for and apply local config files; if not passed, defaults are updated with any config files in the project's root directory

-r, --recursive

run recursively over directories; must be used with --in-place or --diff

-j n, --jobs n

number of parallel jobs; match CPU count if value is less than 1

-p n, --pep8-passes n

maximum number of additional pep8 passes (default: infinite)

-a, --aggressive

enable non-whitespace changes; multiple -a result in more aggressive changes


enable experimental fixes

--exclude globs

exclude file/directory names that match these commaseparated globs


list codes for fixes; used by --ignore and --select

--ignore errors

do not fix these errors/warnings (default: E226,E24,W50,W690)

--select errors

fix only these errors/warnings (e.g. E4,W)

--max-line-length n

set maximum allowed line length (default: 79)

--line-range line line, --range line line

only fix errors found within this inclusive range of line numbers (e.g. 1 99); line numbers are indexed at 1


hang-closing option passed to pycodestyle


change to behavior of exit code. default behavior of return value, 0 is no differences, 1 is error exit. return 2 when add this option. 2 is exists differences.


The full documentation for python3 is maintained as a Texinfo manual. If the info and python3 programs are properly installed at your site, the command info python3 should give you access to the complete manual.

Copied to clipboard