autopep8

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

Tool
PyPI
v2.3.2
4,660stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
71/100Good
Development Activity60
Maintenance52
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture74
Code Quality78
Innovation72
Learning Curve88

autopep8 is a command-line tool that automatically reformats Python source code so it conforms to the PEP 8 style guide. It builds on the pycodestyle checker to detect style violations and then rewrites the offending code, fixing indentation, whitespace, blank lines, and statement layout.

With configurable aggressiveness levels, in-place editing, and diff output, autopep8 fits naturally into editors, pre-commit hooks, and CI pipelines, letting teams enforce a consistent Python style without hand-editing every file.

What You Get

  • A autopep8 command-line entry point that formats files or whole directories in place or to stdout
  • Configurable aggressiveness levels to control how invasive the automatic fixes are
  • Diff mode to preview changes before applying them
  • Selective fixing via --select/--ignore to target specific pycodestyle error codes
  • An importable fix_code API for programmatic formatting

Common Use Cases

  • Automatically cleaning up legacy Python code to satisfy PEP 8
  • Enforcing consistent formatting in pre-commit hooks and CI
  • Formatting code on save from within an editor or IDE integration
  • Bulk-reformatting a codebase before adopting stricter linting

Under The Hood

Architecture - autopep8 is implemented as a single large module (autopep8.py, ~4,650 lines) exposing a main() entry point and a fix_code()/fix_lines() core. It invokes pycodestyle to enumerate style violations, maps each error code to a dedicated fix_* handler, and applies those handlers iteratively over the source until the code stabilizes or the pass limit is reached, then emits in-place edits, a diff, or stdout output.

Tech Stack - Pure Python (requires Python 3.10+), depending on pycodestyle for violation detection and tomli on older interpreters for TOML config parsing. It is packaged with setuptools via pyproject.toml, exposes an autopep8 console script, and uses tox for multi-version test orchestration.

Code Quality - The project is mature and production-stable with a substantial test suite under test/ (including test_autopep8.py and a fixture suite), covering encoding edge cases and many pycodestyle codes. The single-module design keeps everything in one file but is well factored into small per-rule fix functions.

API Design - The developer experience is centered on a well-documented CLI with familiar flags (--in-place, --diff, --aggressive, --select, --ignore), plus a minimal fix_code(source) function for programmatic use. Getting started requires almost no boilerplate, and behavior is predictable and incremental.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search