# autopep8

> A tool that automatically formats Python code to conform to the PEP 8 style guide

- **URL**: https://www.freshcrate.ai/projects/autopep8
- **Author**: pypi
- **Category**: Frameworks
- **Latest version**: `2.3.2` (2026-04-21)
- **License**: Unknown
- **Source**: https://github.com/hhatto/autopep8
- **Homepage**: https://pypi.org/project/autopep8/
- **Language**: Python
- **GitHub**: 4,667 stars, 287 forks
- **Registry**: pypi (`autopep8`)
- **Tags**: `automation`, `format`, `pep8`, `pycodestyle`, `pypi`

## Description

========
autopep8
========

.. image:: https://img.shields.io/pypi/v/autopep8.svg
    :target: https://pypi.org/project/autopep8/
    :alt: PyPI Version

.. image:: https://github.com/hhatto/autopep8/workflows/Python%20package/badge.svg
    :target: https://github.com/hhatto/autopep8/actions
    :alt: Build status

.. image:: https://codecov.io/gh/hhatto/autopep8/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/hhatto/autopep8
    :alt: Code Coverage

autopep8 automatically formats Python code to conform to the `PEP 8`_ style
guide. It uses the pycodestyle_ utility to determine what parts of the code
needs to be formatted. autopep8 is capable of fixing most of the formatting
issues_ that can be reported by pycodestyle.

.. _PEP 8: https://www.python.org/dev/peps/pep-0008/
.. _issues: https://pycodestyle.readthedocs.org/en/latest/intro.html#error-codes

.. contents::


Installation
============

From pip::

    $ pip install --upgrade autopep8

Consider using the ``--user`` option_.

.. _option: https://pip.pypa.io/en/latest/user_guide/#user-installs


Requirements
============

autopep8 requires pycodestyle_.

.. _pycodestyle: https://github.com/PyCQA/pycodestyle


Usage
=====

To modify a file in place (with aggressive level 2)::

    $ autopep8 --in-place --aggressive --aggressive <filename>

Before running autopep8.

.. code-block:: python

    import math, sys;

    def example1():
        ####This is a long comment. This should be wrapped to fit within 72 characters.
        some_tuple=(   1,2, 3,'a'  );
        some_variable={'long':'Long code lines should be wrapped within 79 characters.',
        'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
        'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
        20,300,40000,500000000,60000000000000000]}}
        return (some_tuple, some_variable)
    def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
    class Example3(   object ):
        def __init__    ( self, bar ):
         #Comments should have a space after the hash.
         if bar : bar+=1;  bar=bar* bar   ; return bar
         else:
                        some_string = """
    		           Indentation in multiline strings should not be touched.
    Only actual code should be reindented.
    """
                        return (sys.path, some_string)

After running autopep8.

.. code-block:: python

    import math
    import sys


    def example1():
        # This is a long comment. This should be wrapped to fit within 72
        # characters.
        some_tuple = (1, 2, 3, 'a')
        some_variable = {
            'long': 'Long code lines should be wrapped within 79 characters.',
            'other': [
                math.pi,
                100,
                200,
                300,
                9876543210,
                'This is a long string that goes on'],
            'more': {
                'inner': 'This whole logical line should be wrapped.',
                some_tuple: [
                    1,
                    20,
                    300,
                    40000,
                    500000000,
                    60000000000000000]}}
        return (some_tuple, some_variable)


    def example2(): return ('' in {'f': 2}) in {'has_key() is deprecated': True}


    class Example3(object):
        def __init__(self, bar):
            # Comments should have a space after the hash.
            if bar:
                bar += 1
                bar = bar * bar
                return bar
            else:
                some_string = """
    		           Indentation in multiline strings should not be touched.
    Only actual code should be reindented.
    """
                return (sys.path, some_string)

Options::

    usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]
                    [--ignore-local-config] [-r] [-j n] [-p n] [-a]
                    [--experimental] [--exclude globs] [--list-fixes]
                    [--ignore errors] [--select errors] [--max-line-length n]
                    [--line-range line line] [--hang-closing] [--exit-code]
                    [files [files ...]]

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

    positional arguments:
      files                 files to format or '-' for standard in

    optional arguments:
      -h, --help            show this help message and exit
      --version             show program's version number and exit
      -v, --verbose         print verbose messages; multiple -v result in more
                            verbose messages
      -d, --diff            print the diff for the fixed source
      -i, --in-place        make changes to files in place
      --global-config filename
                            path to a global pep8 config file; if this file does
                            not exist then this is ignored (default:

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `2.3.2` | 2026-04-21 | Low | Imported from PyPI (2.3.2) |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |
| `v2.3.2` | 2025-01-14 | Low | ## What's Changed * Update README.rst: Typo fix by @mrichtarsky in https://github.com/hhatto/autopep8/pull/768 * Bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/hhatto/autopep8/pull/773 * support Python 3.13 and drop 3.8 by @hhatto in https://github.com/hhatto/autopep8/pull/777 * Fix E721 type comparison pattern handling by @hhatto in https://github.com/hhatto/autopep8/pull/776  ## New Contributors * @mrichtarsky made their first contribution in https://github |

## Dependency audit

- **Score**: 86/100
- **Total deps**: 2
- **Resolved**: 1
- **Unresolved**: 1
- **License conflicts**: 0
- **Warnings**: 2
- **Scanned**: 2026-05-25

## Citation

- HTML: https://www.freshcrate.ai/projects/autopep8
- Markdown: https://www.freshcrate.ai/projects/autopep8.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/autopep8/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
