autopep8 – automatically format Python code to follow PEP 8

autopep8 is a Python source code formatter that automatically corrects formatting problems identified by pycodestyle. It helps developers bring existing code into closer alignment with the PEP 8 style guide.

Rather than applying one fixed formatting style, autopep8 identifies specific violations and attempts to correct them. Developers can control which categories of problems are addressed and how aggressively the formatter modifies source code.

The program is useful for improving the consistency of existing projects without requiring an extensive manual cleanup. It can process individual source files or larger collections of code, and provides configuration options suitable for automated development workflows.

This is free and open source software.

Key Features

  • Automatically corrects Python formatting problems identified by pycodestyle.
  • Fixes indentation errors and alignment problems.
  • Removes unnecessary whitespace and corrects spacing around operators and keywords.
  • Adjusts blank lines, continuation indentation and comment formatting.
  • Provides configurable levels of aggressive formatting.
  • Allows individual PEP 8 error and warning codes to be selected or ignored.
  • Supports configurable maximum line lengths and indentation settings.
  • Can format complete files or selected ranges of source lines.
  • Supports recursive processing of directories containing Python code.
  • Offers parallel processing when working with multiple files.
  • Provides diff mode to preview changes without modifying files.
  • Supports in-place formatting or output to standard output.
  • Allows specific lines or sections to be excluded from automatic formatting.
  • Reads settings from pyproject.toml, setup.cfg and other supported configuration files.
  • Provides a Python API for integration with other applications.
  • Supports pre-commit integration for automated source code formatting.

Website: github.com/hhatto/autopep8
Support:
Developer: Hideo Hattori, Steven Myint, Bill Wendling
License: MIT License

autopep8 is written in Python. Learn Python with our recommended free books and free tutorials.


Related Software

Python Code Formatters
RuffExtremely fast Python linter and code formatter
YAPFPython formatter based on clang-format
BlackUncompromising Python code formatter
isortPython utility and library to sort imports
autopep8Formats Python code to conform to the PEP 8 style guide
DarkerApply black reformatting to Python files
PyinkPython code formatter
docformatterAutomatically formats Python docstrings for consistent style
SSortSorts Python statements by dependency for clearer code
reorder-python-importsReorders Python imports into a consistent, readable layout
μsortSorts import statements
eradicateRemove commented-out code from Python files

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted