reorder-python-imports
Tool for reordering python imports
What it is and what it does
reorder-python-imports is a command-line tool that automatically reformats Python import statements according to a consistent style designed to minimize merge conflicts. It separates imports into three sections (standard library, third-party, first-party), places import statements before from imports, splits multi-item from imports into individual lines, and removes duplicates. The tool uses static analysis to understand import classification.
It integrates as a pre-commit hook or standalone CLI tool and supports options for Python version targeting (e.g., --py3-plus to remove obsolete __future__ imports), adding or removing specific imports, replacing imports with alternatives, and handling application-specific module paths. The single-import-per-line style allows multiple developers to modify imports without creating merge conflicts, even when editing the same module.
Use it for:
- Enforce consistent import ordering across a team codebase via pre-commit hooks.
- Automatically remove obsolete __future__ imports when upgrading to newer Python versions.
- Replace compatibility library imports with modern equivalents automatically.
- Reduce merge conflicts when multiple contributors add imports to the same file.
- Rewrite mock and typing imports for newer Python versions automatically.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically reorders Python imports into a standardized format (stdlib, third-party, first-party) using static analysis, with one import per line to reduce merge conflicts.
Yes. Low install friction, permissive MIT license, active maintenance, no known vulnerabilities, and a focused tool that solves a real problem (merge conflicts from import changes). Use it if your team wants deterministic import ordering enforced automatically, especially via pre-commit hooks.
Install
reorder-python-imports on PyPI
pip
pip install reorder-python-importsuv
uv add reorder-python-importspoetry
poetry add reorder-python-importsInstalling reorder-python-imports
Before you install
Low friction: pure Python wheel with a single runtime dependency (classify-imports). Active maintenance with a release 35 days ago and 784 repository stars.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal obligations.
Quickstart
pip install reorder-python-imports
reorder-python-imports myfile.py
# Or add to .pre-commit-config.yaml:
# - repo: https://github.com/asottile/reorder-python-imports
# rev: v3.17.0
# hooks:
# - id: reorder-python-imports
Requires Python 3.10 or later.
Verify before relying
- Performance characteristics when processing large codebases or files with many imports.
- How the static analysis approach differs in practice from similar tools on real-world projects.
- Support for type-checking-only imports and conditional import blocks.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — classify-imports |
| Maintenance | actively maintained — 35 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 147,672/month — #11,053 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: reorder_python_imports-3.17.0-py2.py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
absolufy-importsAutomatically converts relative imports to…
permissive · top 15,000 on PyPI
isortisort sorts Python imports alphabetically and…
permissive · top 1,000 on PyPI
usortμsort sorts Python imports within detected…
permissive · top 5,000 on PyPI
pyupgradeAutomatically rewrites Python source code to…
permissive · top 5,000 on PyPI
classify-importsParses, classifies, and sorts Python import…
permissive · top 15,000 on PyPI
google-pastaParse Python source code into an AST, modify…
permissive · top 1,000 on PyPI
aspy.refactor-importsParses, classifies, and manipulates Python…
permissive · top 15,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
sort-linesAlphabetizes lines in files based on…
permissive · top 15,000 on PyPI
mo-futureProvides a flat-namespace compatibility layer…
copyleft · top 15,000 on PyPI