skillfed

reorder-python-imports

Tool for reordering python imports

reorder-python-imports v3.17.0 147.7K downloads/30d#11,053 on PyPI784
Permissive license MIT Active released

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-imports

uv

uv add reorder-python-imports

poetry

poetry add reorder-python-imports

Installing 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

Programming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

python import reorderingorganize python importsimport sorting toolmerge conflict reductionstatic import analysisimport formatterpython code formatter
import-formattingpre-commit-hookcode-quality

More Quality Assurance packages