LinuxCommandLibrary

autopep8

Automatically format Python code to PEP 8 style

TLDR

Format Python file

$ autopep8 --in-place [file.py]
copy
Format with aggressive fixes
$ autopep8 --in-place --aggressive --aggressive [file.py]
copy
Show diff instead of modifying
$ autopep8 --diff [file.py]
copy
Format recursively
$ autopep8 --in-place --recursive [directory/]
copy
Select specific fixes
$ autopep8 --select=[E501,W293] --in-place [file.py]
copy

SYNOPSIS

autopep8 [--in-place] [--aggressive] [options] files

DESCRIPTION

autopep8 automatically formats Python code to conform to PEP 8 style guide. It fixes issues like whitespace, indentation, and line length while preserving code semantics.
The tool integrates with editors and CI pipelines to enforce consistent Python style.

PARAMETERS

-i, --in-place

Modify files in place
-d, --diff
Print diff instead of modifying
-r, --recursive
Process directories recursively
-a, --aggressive
More aggressive fixes (repeatable for more aggression)
--select=errors
Fix only specified errors
--ignore=errors
Ignore specified errors
--max-line-length=n
Maximum line length (default: 79)
--range start end
Only fix lines in range
--exclude patterns
Exclude file patterns

CONFIGURATION

setup.cfg

Project-level configuration under `[pycodestyle]` section.
pyproject.toml
Project-level configuration under `[tool.autopep8]` section.
~/.config/pycodestyle
User-level default configuration for pycodestyle rules.

ERROR CODES

Based on PEP 8:
- E: Errors
- W: Warnings
- Examples: E501 (line too long), W291 (trailing whitespace)

CAVEATS

May conflict with other formatters like black. Aggressive mode can change code logic in rare cases. Review changes before committing. Black is now more popular for opinionated formatting.

HISTORY

autopep8 was created by Hideo Hattori to provide automatic PEP 8 compliance, released around 2010.

SEE ALSO

black(1), isort(1), flake8(1)

> TERMINAL_GEAR

Curated for the Linux community

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

$239.99
nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

$129.95
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

$169.99
New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

$54.00
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00