Registry / testing / autopep8

autopep8

JSON →
library2.3.2pypypi✓ verified 25d ago

autopep8 is a tool that automatically formats Python code to conform to the PEP 8 style guide. It fixes most PEP 8 issues that can be automatically fixed. Currently at version 2.3.2, it maintains an active release schedule with several updates per year addressing bug fixes, new Python version support, and rule enhancements.

pip install autopep8
INSTALL
IMPORT
SIG · AUTOPEP8
A
autopep8
testingpythonv2.3.2
Install
1.7s avg
Import
94ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.098s · 18.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.090s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fix_code
from autopep8 import fix_code
import autopep8

Demonstrates programmatic use of `autopep8.fix_code` with default and custom options. It also mentions the common command-line interface usage.

import autopep8 # Sample code with PEP8 violations source_code = """ def my_func ( arg1 , arg2 ): if (True): # E712 comparison to True return arg1+arg2 """ print("Original code:") print(source_code) # Fix the code with default options # An empty dictionary for options applies default autopep8 behavior. fixed_code = autopep8.fix_code(source_code, options={}) print("\nFixed code (default options):") print(fixed_code) # Fix with specific options, e.g., higher aggressiveness # Note: Certain fixes (like E712) may require higher aggressive levels. options_aggressive = {'aggressive': 1} fixed_code_aggressive = autopep8.fix_code(source_code, options=options_aggressive) print("\nFixed code (aggressive=1):") print(fixed_code_aggressive) # Command line usage example (run in your shell): # echo "def my_func ( arg1 , arg2 ):\n return arg1+arg2" > example.py # autopep8 --in-place example.py # cat example.py # Will show the formatted code
autopep8 --version
Debug
Known issues
breakingPython version compatibility has changed. autopep8 v2.3.2 dropped support for Python 3.8 and now requires Python 3.9+. Previous versions like v2.1.0 dropped Python 3.7 support.
fix
Ensure your Python environment meets the minimum requirement (Python 3.9+ for latest autopep8). If you need to support older Python versions, pin autopep8 to a compatible older release (e.g., `<2.3.2` for Python 3.8).
affects: >=2.1.0 (for 3.7 drop), >=2.3.2 (for 3.8 drop)
deprecatedThe `--experimental` command-line option was deprecated in autopep8 v2.2.0.
fix
Remove the `--experimental` option from your `autopep8` commands or configurations. Functionality that was previously experimental might now be enabled by default or handled through different options (e.g., `--aggressive`).
affects: >=2.2.0
gotchaautopep8 has a direct dependency on `pycodestyle`, and specific versions of `autopep8` might require a minimum version of `pycodestyle`. For instance, autopep8 v2.3.0 requires `pycodestyle v2.12.0+`.
fix
When upgrading `autopep8`, it's recommended to upgrade `pycodestyle` simultaneously or ensure you meet the minimum required version. Use `pip install --upgrade autopep8 pycodestyle`.
affects: >=2.3.0
gotchaautopep8 uses `pyproject.toml` (under `[tool.autopep8]`) or `setup.cfg` (under `[autopep8]`) for configuration. It does not look for a dedicated `.autopep8` or `autopep8.cfg` file.
fix
If you are migrating from other tools or expecting a dedicated configuration file, place your autopep8 options within your `pyproject.toml` or `setup.cfg` file under the appropriate section.
affects: All versions
gotchaautopep8 fixes many, but not all, PEP 8 issues. The `--aggressive` option enables more fixes, but even with multiple `--aggressive` flags, common violations like E712 (explicit comparison to `True`/`False`/`None`) may not be automatically corrected, requiring manual intervention.
fix
Understand autopep8's limitations. While `--aggressive` helps with some issues, common violations such as E712 (`if (True)`) often require manual correction. Always review changes made by automated tools.
affects: All versions
Upgrade
Version history
2.3.2latest on PyPI · released Jan 14, 2025
Audit
Dependencies
pycodestylerequiredCore dependency for identifying PEP 8 violations; specific versions are required by autopep8 releases.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
2
Resources
autopep8 — pip install autopep8 · libregistry