{"id":13790789,"url":"https://github.com/pycqa/autoflake","last_synced_at":"2026-02-20T07:00:49.659Z","repository":{"id":6107866,"uuid":"7335450","full_name":"PyCQA/autoflake","owner":"PyCQA","description":"Removes unused imports and unused variables as reported by pyflakes","archived":false,"fork":false,"pushed_at":"2026-01-23T05:52:41.000Z","size":684,"stargazers_count":952,"open_issues_count":47,"forks_count":83,"subscribers_count":11,"default_branch":"main","last_synced_at":"2026-02-12T22:48:56.800Z","etag":null,"topics":["formatter","hacktoberfest","linter","pyflakes","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/autoflake/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PyCQA.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2012-12-27T03:40:17.000Z","updated_at":"2026-02-11T16:34:37.000Z","dependencies_parsed_at":"2023-12-07T01:55:08.574Z","dependency_job_id":"6d2683c9-ac12-4a2c-a548-5d286c7b764d","html_url":"https://github.com/PyCQA/autoflake","commit_stats":{"total_commits":628,"total_committers":38,"mean_commits":"16.526315789473685","dds":0.339171974522293,"last_synced_commit":"23cfe6fb386a3ac3c092262df09b20c388228123"},"previous_names":["myint/autoflake"],"tags_count":63,"template":false,"template_full_name":null,"purl":"pkg:github/PyCQA/autoflake","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fautoflake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fautoflake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fautoflake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fautoflake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PyCQA","download_url":"https://codeload.github.com/PyCQA/autoflake/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fautoflake/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29643960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T05:21:04.652Z","status":"ssl_error","status_checked_at":"2026-02-20T05:21:04.238Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","hacktoberfest","linter","pyflakes","python"],"created_at":"2024-08-03T22:00:51.271Z","updated_at":"2026-02-20T07:00:49.652Z","avatar_url":"https://github.com/PyCQA.png","language":"Python","readme":"# autoflake\n\n[![Build Status](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml)\n\n## Introduction\n\n_autoflake_ removes unused imports and unused variables from Python code. It\nmakes use of [pyflakes](https://pypi.org/pypi/pyflakes) to do this.\n\nBy default, autoflake only removes unused imports for modules that are part of\nthe standard library. (Other modules may have side effects that make them\nunsafe to remove automatically.) Removal of unused variables is also disabled\nby default.\n\nautoflake also removes useless ``pass`` statements by default.\n\n## Example\n\nRunning autoflake on the below example\n\n```\n$ autoflake --in-place --remove-unused-variables example.py\n```\n\n```python\nimport math\nimport re\nimport os\nimport random\nimport multiprocessing\nimport grp, pwd, platform\nimport subprocess, sys\n\n\ndef foo():\n    from abc import ABCMeta, WeakSet\n    try:\n        import multiprocessing\n        print(multiprocessing.cpu_count())\n    except ImportError as exception:\n        print(sys.version)\n    return math.pi\n```\n\nresults in\n\n```python\nimport math\nimport sys\n\n\ndef foo():\n    try:\n        import multiprocessing\n        print(multiprocessing.cpu_count())\n    except ImportError:\n        print(sys.version)\n    return math.pi\n```\n\n\n## Installation\n\n```\n$ pip install --upgrade autoflake\n```\n\n\n## Advanced usage\n\nTo allow autoflake to remove additional unused imports (other than\nthan those from the standard library), use the ``--imports`` option. It\naccepts a comma-separated list of names:\n\n```\n$ autoflake --imports=django,requests,urllib3 \u003cfilename\u003e\n```\n\nTo remove all unused imports (whether or not they are from the standard\nlibrary), use the ``--remove-all-unused-imports`` option.\n\nTo remove unused variables, use the ``--remove-unused-variables`` option.\n\nBelow is the full listing of options:\n\n```\nusage: autoflake [-h] [-c | -cd] [-r] [-j n] [--exclude globs] [--imports IMPORTS] [--expand-star-imports] [--remove-all-unused-imports] [--ignore-init-module-imports] [--remove-duplicate-keys] [--remove-unused-variables]\n                 [--remove-rhs-for-unused-variables] [--ignore-pass-statements] [--ignore-pass-after-docstring] [--version] [--quiet] [-v] [--stdin-display-name STDIN_DISPLAY_NAME] [--config CONFIG_FILE] [-i | -s]\n                 files [files ...]\n\nRemoves unused imports and unused variables as reported by pyflakes.\n\npositional arguments:\n  files                 files to format\n\noptions:\n  -h, --help            show this help message and exit\n  -c, --check           return error code if changes are needed\n  -cd, --check-diff     return error code if changes are needed, also display file diffs\n  -r, --recursive       drill down directories recursively\n  -j n, --jobs n        number of parallel jobs; match CPU count if value is 0 (default: 0)\n  --exclude globs       exclude file/directory names that match these comma-separated globs\n  --imports IMPORTS     by default, only unused standard library imports are removed; specify a comma-separated list of additional modules/packages\n  --expand-star-imports\n                        expand wildcard star imports with undefined names; this only triggers if there is only one star import in the file; this is skipped if there are any uses of `__all__` or `del` in the file\n  --remove-all-unused-imports\n                        remove all unused imports (not just those from the standard library)\n  --ignore-init-module-imports\n                        exclude __init__.py when removing unused imports\n  --remove-duplicate-keys\n                        remove all duplicate keys in objects\n  --remove-unused-variables\n                        remove unused variables\n  --remove-rhs-for-unused-variables\n                        remove RHS of statements when removing unused variables (unsafe)\n  --ignore-pass-statements\n                        ignore all pass statements\n  --ignore-pass-after-docstring\n                        ignore pass statements after a newline ending on '\"\"\"'\n  --version             show program's version number and exit\n  --quiet               Suppress output if there are no issues\n  -v, --verbose         print more verbose logs (you can repeat `-v` to make it more verbose)\n  --stdin-display-name STDIN_DISPLAY_NAME\n                        the name used when processing input from stdin\n  --config CONFIG_FILE  Explicitly set the config file instead of auto determining based on file location\n  -i, --in-place        make changes to files instead of printing diffs\n  -s, --stdout          print changed text to stdout. defaults to true when formatting stdin, or to false otherwise\n```\n\nTo ignore the file, you can also add a comment to the top of the file:\n```python\n# autoflake: skip_file\nimport os\n```\n\n## Configuration\n\nConfigure default arguments using a `pyproject.toml` file:\n\n```toml\n[tool.autoflake]\ncheck = true\nimports = [\"django\", \"requests\", \"urllib3\"]\n```\n\nOr a `setup.cfg` file:\n\n```ini\n[autoflake]\ncheck=true\nimports=django,requests,urllib3\n```\n\nThe name of the configuration parameters match the flags (e.g. use the\nparameter `expand-star-imports` for the flag `--expand-star-imports`).\n\n## Tests\n\nTo run the unit tests::\n\n```\n$ ./test_autoflake.py\n```\n\nThere is also a fuzz test, which runs against any collection of given Python\nfiles. It tests autoflake against the files and checks how well it does by\nrunning pyflakes on the file before and after. The test fails if the pyflakes\nresults change for the worse. (This is done in memory. The actual files are\nleft untouched.)::\n\n```\n$ ./test_fuzz.py --verbose\n```\n\n## Excluding specific lines\n\nIt might be the case that you have some imports for their side effects, even\nif you are not using them directly in that file.\n\nThat is common, for example, in Flask based applications. In where you import\nPython modules (files) that imported a main ``app``, to have them included in\nthe routes.\n\nFor example:\n\n```python\nfrom .endpoints import role, token, user, utils\n```\n\nAs those imports are not being used directly, if you are using the option\n``--remove-all-unused-imports``, they would be removed.\n\nTo prevent that, without having to exclude the entire file, you can add a\n``# noqa`` comment at the end of the line, like:\n\n```python\nfrom .endpoints import role, token, user, utils  # noqa\n```\n\nThat line will instruct ``autoflake`` to let that specific line as is.\n\n\n## Using [pre-commit](https://pre-commit.com) hooks\n\nAdd the following to your `.pre-commit-config.yaml`\n\n```yaml\n-   repo: https://github.com/PyCQA/autoflake\n    rev: v2.3.3\n    hooks:\n    -   id: autoflake\n```\n\nWhen customizing the arguments, make sure you include `--in-place` in the list\nof arguments:\n\n```yaml\n-   repo: https://github.com/PyCQA/autoflake\n    rev: v2.3.3\n    hooks:\n    -   id: autoflake\n        args: [--remove-all-unused-imports, --in-place]\n```\n","funding_links":[],"categories":["By Environment"],"sub_categories":["Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycqa%2Fautoflake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpycqa%2Fautoflake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycqa%2Fautoflake/lists"}