--- id: autoflake version: "2.3.3" license: MIT license_treatment: permissive maintenance: active --- # autoflake — Removes unused imports and unused variables License: permissive · Maintenance: active · Downloads: 6.5M/mo ## What it is and what it does autoflake is a command-line tool that automatically detects and removes unused imports and variables from Python source files. It uses pyflakes to identify dead code and by default only removes unused imports from the standard library, leaving third-party imports untouched unless explicitly configured. This conservative default prevents accidental removal of imports that may have side effects. The tool is typically used as a standalone formatter or integrated into pre-commit hooks to enforce code cleanliness. It supports configuration via pyproject.toml or setup.cfg, can operate on single files or recursively through directories, and offers fine-grained control over what gets removed—from all unused imports to unused variables to duplicate dictionary keys. It also removes useless pass statements by default. Use it for: - Run as a pre-commit hook to automatically clean up unused imports before code review. - Integrate into CI/CD pipelines to check for unused code and fail builds when cleanup is needed. - Refactor legacy Python codebases to remove accumulated dead imports and variables. - Configure with --imports to safely remove unused third-party imports in specific projects. - Use --expand-star-imports to replace wildcard imports with explicit names for clarity. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. autoflake removes unused imports and unused variables from Python code by analyzing it with pyflakes, and optionally removes useless pass statements. Yes. autoflake is a lightweight, actively maintained tool with no security vulnerabilities, minimal dependencies, and a permissive MIT license. It solves a real code-quality problem with low friction and is well-suited for both individual developers and teams integrating it into CI/CD workflows. ## Install pip install autoflake uv add autoflake poetry add autoflake ## Installing autoflake Before you install: Low install friction with only 2 runtime dependencies (pyflakes and tomli). The project is actively maintained with a recent release on 2026-02-20 and steady commit activity. License in practice: MIT license is permissive, allowing use in commercial and private projects with minimal restrictions. Quickstart: pip install autoflake autoflake --in-place --remove-unused-variables example.py Requires Python >=3.10. Verify before relying: - Whether the tool safely handles imports with side effects beyond the documented --imports and # noqa mechanisms. - Performance characteristics when processing large codebases or using parallel jobs (-j flag). ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 6.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags remove unused imports python, clean up unused variables, python code cleanup tool, automate import removal, unused code detection, python linting automation, code quality cleanup, code-cleanup, pre-commit-ready, linting [View on SkillFed](https://skillfed.io/packages/autoflake) · [View on PyPI](https://pypi.org/project/autoflake/)