{"id":21874,"library":"reorder-python-imports","title":"reorder-python-imports","description":"A tool for automatically reordering Python imports into a consistent style (stdlib, third-party, first-party) and removing unused imports. Current version: 3.16.0. Released irregularly, maintained by asottile.","status":"active","version":"3.16.0","language":"python","source_language":"en","source_url":"https://github.com/asottile/reorder-python-imports","tags":["imports","formatting","linting","ast"],"install":[{"cmd":"pip install reorder-python-imports","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Main entry point; used as a library or CLI.","symbol":"reorder_python_imports","correct":"import reorder_python_imports"}],"quickstart":{"code":"# As a CLI tool:\n# reorder-python-imports myfile.py\n\n# As a library:\nimport reorder_python_imports\n\ncode = \"\"\"import os\nimport sys\nimport requests\n\"\"\"\nresult = reorder_python_imports.fix_file_contents(code)\nprint(result)","lang":"python","description":"Reorder imports via CLI or programmatically. The fix_file_contents function returns reordered code."},"warnings":[{"fix":"Pin to version 2.x if needed: pip install 'reorder-python-imports<3'","message":"Version 3.x dropped Python 2 support and changed default behavior to remove unused imports. If relying on version 2.x behavior, pin to 'reorder-python-imports<3'.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Manually verify that imports used dynamically are not removed. Use '--no-remove-unused' flag to disable removal.","message":"The tool reorders imports within a single file only; it does not handle cross-module analysis. Unused imports are removed based on simple AST check, which may remove imports used via eval or sys.modules.","severity":"gotcha","affected_versions":"all"},{"fix":"Place type-checking imports in a separate block or use '# noqa' comments judiciously; review output.","message":"Import comments or inline type hints (e.g., 'from typing import TYPE_CHECKING') may be lost if not recognized. The tool strips comments and may reorder them incorrectly.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run: pip install reorder-python-imports","cause":"Package not installed or installed with a different name.","error":"ModuleNotFoundError: No module named 'reorder_python_imports'"},{"fix":"Check CLI options with: reorder-python-imports --help","cause":"Using a flag that does not exist in current version.","error":"reorder-python-imports: error: unrecognized arguments: --amazing-option"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}