Registry / testing / reorder-python-imports

reorder-python-imports

JSON →
library3.16.0pypypi✓ verified 87d ago

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.

pip install reorder-python-imports
INSTALL
IMPORT
SIG · REORDER-PYTHON-IMP
R
reorder-python-imports
testingpythonv3.16.0
Install
1.6s avg
Import
29ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.16.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.032s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.026s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

reorder_python_imports
import reorder_python_imports
Main entry point; used as a library or CLI.

Reorder imports via CLI or programmatically. The fix_file_contents function returns reordered code.

# As a CLI tool: # reorder-python-imports myfile.py # As a library: import reorder_python_imports code = """import os import sys import requests """ result = reorder_python_imports.fix_file_contents(code) print(result)
reorder-python-imports --version
Debug
Known issues
breakingVersion 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'.
fix
Pin to version 2.x if needed: pip install 'reorder-python-imports<3'
affects: >=3.0.0
gotchaThe 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.
fix
Manually verify that imports used dynamically are not removed. Use '--no-remove-unused' flag to disable removal.
affects: all
gotchaImport 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.
fix
Place type-checking imports in a separate block or use '# noqa' comments judiciously; review output.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'reorder_python_imports'
Package not installed or installed with a different name.
fix
Run: pip install reorder-python-imports
reorder-python-imports: error: unrecognized arguments: --amazing-option
Using a flag that does not exist in current version.
fix
Check CLI options with: reorder-python-imports --help
Upgrade
Version history
3.16.0latest on PyPI · released Oct 9, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
reorder-python-imports — pip install reorder-python-imports · libregistry