Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install autoflake

How to install autoflake

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install autoflake
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
0.6.1 Available View build log
0.4.4 Available View build log
0.6.1 Available View build log
0.4.4 Available View build log
Expat License
Depended by
Lastest release
version 0.6.1 on Sep 20th, 2013
Build status Test coverage status


autoflake removes unused imports and unused variables from Python code. It makes use of pyflakes to do this.

By default, autoflake only removes unused imports for modules that are part of the standard library. (Other modules may have side effects that make them unsafe to remove automatically.) Removal of unused variables is also disabled by default.

autoflake also removes useless pass statements.


Running autoflake on the below example:

$ autoflake --in-place --remove-unused-variables example.py

System Message: ERROR/3 (<string>, line 37)

Unknown directive type "code-block".

.. code-block:: python

    import math
    import re
    import os
    import random
    import multiprocessing
    import grp, pwd, platform
    import subprocess, sys

    def foo():
        from abc import ABCMeta, WeakSet
            import multiprocessing
        except ImportError as exception:
        return math.pi

results in

System Message: ERROR/3 (<string>, line 59)

Unknown directive type "code-block".

.. code-block:: python

    import math
    import sys

    def foo():
            import multiprocessing
        except ImportError:
        return math.pi


$ pip install --upgrade autoflake

Advanced usage

To allow autoflake to remove additional unused imports (other than than those from the standard library), use the --imports option. It accepts a comma-separated list of names:

$ autoflake --imports=django,requests,urllib3 <filename>

To remove all unused imports (whether or not they are from the standard library), use the --remove-all-unused-imports option.

To remove unused variables, use the --remove-unused-variables option.

Below is the full listing of options:

usage: autoflake [-h] [-i] [-r] [--imports IMPORTS]
                 [--remove-all-unused-imports] [--remove-unused-variables]
                 files [files ...]

Removes unused imports as reported by pyflakes.

positional arguments:
  files                 files to format

optional arguments:
  -h, --help            show this help message and exit
  -i, --in-place        make changes to files instead of printing diffs
  -r, --recursive       drill down directories recursively
  --imports IMPORTS     by default, only unused standard library imports are
                        removed; specify a comma-separated list of additional
                        remove all unused imports (not just those from the
                        standard library
                        remove unused variables
  --version             show program's version number and exit


To run the unit tests:

$ ./test_autoflake.py

There is also an acid test, which runs against any collection of given Python files. It tests autoflake against the files and checks how well it does by running pyflakes on the file before and after. The test fails if the pyflakes results change for the worse. (This is done in memory. The actual files are left untouched.):

$ ./test_acid.py --verbose

Subscribe to package updates

Last updated Sep 20th, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.