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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.098s · 18.4MB
glibcpy 3.10–3.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.fixEnsure 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.fixRemove 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+`.fixWhen 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.fixIf 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.fixUnderstand 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.