{"id":1340,"library":"autopep8","title":"autopep8","description":"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.","status":"active","version":"2.3.2","language":"en","source_language":"en","source_url":"https://github.com/hhatto/autopep8","tags":["linter","formatter","code-quality","pep8","developer-tools"],"install":[{"cmd":"pip install autopep8","lang":"bash","label":"Install autopep8"}],"dependencies":[{"reason":"Core dependency for identifying PEP 8 violations; specific versions are required by autopep8 releases.","package":"pycodestyle","optional":false}],"imports":[{"note":"Primary function for programmatic code fixing. The 'options' argument expects a dictionary or an argparse.Namespace object.","symbol":"fix_code","correct":"import autopep8\nfixed_code = autopep8.fix_code(source, options={})"}],"quickstart":{"code":"import autopep8\n\n# Sample code with PEP8 violations\nsource_code = \"\"\"\ndef   my_func ( arg1 ,  arg2 ):\n    if (True): # E712 comparison to True\n        return arg1+arg2\n\"\"\"\n\nprint(\"Original code:\")\nprint(source_code)\n\n# Fix the code with default options\n# An empty dictionary for options applies default autopep8 behavior.\nfixed_code = autopep8.fix_code(source_code, options={})\nprint(\"\\nFixed code (default options):\")\nprint(fixed_code)\n\n# Fix with specific options, e.g., higher aggressiveness\n# Note: Certain fixes (like E712) may require higher aggressive levels.\noptions_aggressive = {'aggressive': 1}\nfixed_code_aggressive = autopep8.fix_code(source_code, options=options_aggressive)\nprint(\"\\nFixed code (aggressive=1):\")\nprint(fixed_code_aggressive)\n\n# Command line usage example (run in your shell):\n# echo \"def   my_func ( arg1 ,  arg2 ):\\n    return arg1+arg2\" > example.py\n# autopep8 --in-place example.py\n# cat example.py # Will show the formatted code\n","lang":"python","description":"Demonstrates programmatic use of `autopep8.fix_code` with default and custom options. It also mentions the common command-line interface usage."},"warnings":[{"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).","message":"Python 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.","severity":"breaking","affected_versions":">=2.1.0 (for 3.7 drop), >=2.3.2 (for 3.8 drop)"},{"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`).","message":"The `--experimental` command-line option was deprecated in autopep8 v2.2.0.","severity":"deprecated","affected_versions":">=2.2.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`.","message":"autopep8 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+`.","severity":"gotcha","affected_versions":">=2.3.0"},{"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.","message":"autopep8 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Understand the limitations of automatic formatting. Start without `--aggressive`, then try `--aggressive` or `--aggressive --aggressive` if more issues persist. Always review changes made by automated tools.","message":"autopep8 fixes most, but not all, PEP 8 issues automatically. The `--aggressive` option (which can be specified multiple times for higher levels of aggressiveness) is required for certain complex fixes, but even then, some issues might require manual intervention.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}