autopep8

Automatic PEP 8 code formatter for Python — fixes style violations detected by pycodestyle (formerly pep8). autopep8 features: fix_code() for programmatic use, --in-place file modification, --diff for showing changes, --select for specific PEP 8 violations, --ignore for skipping rules, --max-line-length for line length limit, --aggressive for more unsafe fixes (up to 3 levels), pyproject.toml/setup.cfg configuration, recursive directory fixing, --list-fixes for available fixes, and full PEP 8 compliance targeting.

Evaluated Mar 06, 2026 (0d ago) v2.x
Homepage ↗ Repo ↗ Developer Tools python autopep8 pep8 formatting code-style fixer pycodestyle
⚙ Agent Friendliness
66
/ 100
Can an agent use this?
🔒 Security
91
/ 100
Is it safe for agents?
⚡ Reliability
82
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
82
Error Messages
80
Auth Simplicity
99
Rate Limits
99

🔒 Security

TLS Enforcement
92
Auth Strength
92
Scope Granularity
90
Dep. Hygiene
88
Secret Handling
92

Code formatting tool that modifies Python files. No network calls. --in-place modifies files directly — ensure version control before running. autopep8 level 3 aggressive may change code behavior — review changes carefully before applying to security-sensitive code.

⚡ Reliability

Uptime/SLA
80
Version Stability
82
Breaking Changes
82
Error Recovery
82
AF Security Reliability

Best When

Automatically fixing PEP 8 style violations without opinionated reformatting — autopep8 makes minimal changes to fix violations while preserving code structure, unlike black which reformats everything.

Avoid When

Opinionated reformatting (use black), import sorting (use isort), or fast linting without fixing (use ruff).

Use Cases

  • Agent code auto-fix — subprocess.run(['autopep8', '--in-place', '--aggressive', 'src/agent.py'], check=True) — fix file in place; agent CI pipeline auto-fixes PEP 8 violations; --aggressive enables more comprehensive fixes including unused imports and blank lines
  • Agent programmatic fixing — import autopep8; fixed = autopep8.fix_code(source_code, options={'max_line_length': 100, 'aggressive': 1}); with open('output.py', 'w') as f: f.write(fixed) — fix code string; agent code generation tool reformats output before saving
  • Agent diff preview — result = subprocess.run(['autopep8', '--diff', 'src/'], capture_output=True, text=True); print(result.stdout) — show changes without applying; agent CI shows what would change; reviewers approve before autopep8 modifies files
  • Agent selective fixes — subprocess.run(['autopep8', '--in-place', '--select=E1,E2,W', 'src/']) — only whitespace and indentation fixes; agent applies safe fixes only; avoids aggressive changes that might change logic; E1/E2=indentation, W=warnings
  • Agent pre-commit integration — .pre-commit-config.yaml: repos: - repo: https://github.com/pre-commit/mirrors-autopep8, rev: v2.x.x, hooks: - id: autopep8, args: ['--in-place', '--aggressive', '--max-line-length=100'] — automatic PEP 8 fixing on commit; agent developer workflow

Not For

  • Opinionated formatting — autopep8 only fixes PEP 8 violations; for strongly opinionated reformatting use black
  • Import sorting — autopep8 doesn't sort imports; use isort for import ordering
  • Fast linting — autopep8 is a fixer not a linter; for fast linting use ruff

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No auth — local code formatting tool.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

autopep8 is MIT licensed. Free for all use.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • aggressive level 1 vs 2 vs 3 has risk gradient — --aggressive (level 1): safe whitespace fixes; --aggressive --aggressive (level 2): fixes some logical issues; --aggressive x3: may change code behavior; agent CI should use level 1 for safety; test thoroughly before using levels 2-3 on production code
  • --in-place modifies files directly — autopep8 --in-place changes source files; agent must git commit before running or changes may be lost; use --diff first to preview; --in-place has no backup option — ensure files are in version control before running
  • autopep8 slower than ruff for same fixes — ruff --fix is 10-100x faster than autopep8; agent CI using autopep8 for large codebases should consider ruff as faster alternative; ruff implements same PEP 8 rules with better performance; autopep8 advantage: more mature fix implementations for edge cases
  • Conflicts with black — autopep8 and black applied to same file can create endless reformatting loops; autopep8 may add trailing whitespace or blank lines that black removes; use one formatter, not both; recommended: black alone, or autopep8 alone; configure both with consistent max_line_length if using both
  • select= and ignore= use pycodestyle codes — --select=E501 selects line-too-long errors only; codes follow pycodestyle: E=errors, W=warnings, specific: E501=line too long, E302=expected 2 blank lines; agent code must know pycodestyle codes for targeted fixing; --list-fixes shows all available
  • fix_code() input must be string not bytes — autopep8.fix_code(b'code') raises TypeError; must be: autopep8.fix_code(source.decode()); agent code reading files must decode before passing to fix_code(); returns fixed string (not bytes)

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for autopep8.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered