Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Static Analysis & Code Quality
  3. autoflake

autoflake

MITPythonv2.3.3

Removes unused imports and unused variables from Python code using pyflakes.

Visit WebsiteGitHubGitHub
956 stars86 forks0 contributors

What is autoflake?

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.

Target Audience

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.

Value Proposition

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.

Overview

Removes unused imports and unused variables as reported by pyflakes

Use Cases

Best For

  • Automatically cleaning up imports in legacy Python codebases
  • Removing dead code as part of pre-commit hooks
  • Maintaining import hygiene in large Python projects
  • Preparing code for production by eliminating unused variables
  • Integrating with CI/CD pipelines for code quality checks
  • Reducing noise in code reviews by removing unnecessary imports

Not Ideal For

  • Projects with extensive use of imports for side effects (e.g., Flask app initialization) without careful configuration via # noqa comments
  • Dynamic Python codebases where imports are generated or manipulated at runtime, as static analysis may fail to detect usage
  • Teams needing comprehensive code refactoring beyond import and variable cleanup, such as style fixes or logic optimization
  • Environments requiring real-time linting feedback in IDEs, since Autoflake is a command-line tool without built-in editor integration

Pros & Cons

Pros

Conservative Safety Defaults

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.

Flexible Configuration Options

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.

Seamless Workflow 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.

Selective Line Preservation

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.

Cons

Dependent on Pyflakes Limitations

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.

Manual Setup for Non-Standard Imports

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.

Limited Scope of Cleanup

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.

Frequently Asked Questions

Quick Stats

Stars956
Forks86
Contributors0
Open Issues39
Last commit27 days ago
CreatedSince 2012

Tags

#hacktoberfest#code-cleanup#pre-commit#linter#python#code-quality#dead-code-removal#development-tools#static-analysis#formatter

Built With

P
Python

Links & Resources

Website

Included in

Static Analysis & Code Quality14.5k
Auto-fetched 20 hours ago

Related Projects

PHP ParserPHP Parser

A PHP parser written in PHP

Stars17,430
Forks1,122
Last commit2 months ago
TypeScript ESLintTypeScript ESLint

:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript

Stars16,245
Forks2,905
Last commit1 day ago
pyrightpyright

Static Type Checker for Python

Stars15,436
Forks1,784
Last commit5 days ago
ReviewdogReviewdog

🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

Stars9,302
Forks488
Last commit2 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub