Removes unused imports and unused variables from Python code using pyflakes.
Autoflake is a Python command-line tool that automatically removes unused imports and unused variables from Python code. It uses pyflakes for static analysis to identify dead code elements and clean them up, helping developers maintain cleaner codebases with less manual effort.
Python developers and teams looking to automate code cleanup in their projects, particularly those using linters like pyflakes and wanting to integrate dead code removal into their development workflow.
Autoflake provides a focused, reliable way to automatically clean Python code with sensible defaults that prioritize safety, while offering configuration options for more aggressive cleaning when needed. It integrates easily with existing tools and workflows.
Removes unused imports and unused variables as reported by pyflakes
By default, Autoflake only removes unused imports from the standard library, preventing accidental removal of third-party modules with side effects, as emphasized in the README's philosophy section.
It offers flags like --imports and --remove-all-unused-imports to customize cleanup aggressiveness, and supports configuration via pyproject.toml or setup.cfg for seamless integration.
Autoflake integrates with pre-commit hooks and has a --check mode for CI/CD pipelines, making it easy to automate code quality checks without manual intervention.
Using # noqa comments, developers can exclude specific imports from removal, which is crucial for intentional side effects, as explained in the 'Excluding specific lines' section.
Autoflake relies on pyflakes for detection, so it can't identify unused code that pyflakes misses, such as in complex metaprogramming or dynamic import scenarios.
For removing unused third-party imports, users must explicitly configure the tool with --imports or --remove-all-unused-imports, adding overhead compared to more aggressive default settings.
It only handles unused imports and variables, not other code quality issues like style violations or logic errors, requiring additional tools like black or flake8 for comprehensive linting.
A PHP parser written in PHP
:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
Static Type Checker for Python
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.