aspy.refactor-imports
Utilities for refactoring imports in python-like syntax.
What it is and what it does
aspy.refactor_imports provides utilities to parse and manipulate Python import statements as first-class objects. It lets you construct import objects from strings, split multi-import statements into individual ones, sort imports according to custom rules, and classify imports by type (FUTURE, BUILTIN, THIRD_PARTY, APPLICATION). The package is built on a single runtime dependency, cached-property, and supports Python 3.7 through 3.10 on CPython and PyPy.
The package is now maintained in legacy status: the author has rewritten and renamed it for version 4 and beyond. Existing code using aspy.refactor_imports will continue to work, but new projects should consider the renamed version instead. It remains useful for codebases already integrated with it or for tools that need fine-grained control over import parsing and sorting.
Use it for:
- Refactor import statements in a codebase to enforce consistent ordering and grouping conventions.
- Build linting or formatting tools that need to parse and manipulate imports programmatically.
- Classify imports by category (stdlib, third-party, local) to organize or validate import blocks.
- Split comma-separated import statements into individual import lines for readability.
- Sort imports according to custom rules (e.g., stdlib before third-party before application code).
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses, classifies, and manipulates Python import statements as structured objects, enabling programmatic refactoring of imports in code.
Yes, if you are maintaining or extending existing code that already uses aspy.refactor_imports. No, if starting a new project—use the renamed version instead. The package is stable and has no known vulnerabilities, but it is in legacy maintenance mode with no active development beyond bug fixes.
Install
aspy-refactor-imports on PyPI
pip
pip install aspy-refactor-importsuv
uv add aspy-refactor-importspoetry
poetry add aspy-refactor-importsInstalling aspy.refactor-imports
Before you install
Low friction: pure Python wheel with a single runtime dependency (cached-property). Maintenance is active with recent commits, though the latest release was in 2022; the package is stable but superseded by a newer version.
License in practice
MIT license permits commercial and private use with minimal restrictions—suitable for most projects.
Quickstart
pip install aspy.refactor_imports
from aspy.refactor_imports.import_obj import FromImport
obj = FromImport.from_str('from foo import bar')
print(obj.to_text())
Verify before relying
- Whether migration to the renamed version requires code changes
- Performance characteristics when processing large import blocks or many files
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — cached-property |
| Maintenance | actively maintained — 1,505 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 122,598/month — #11,945 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aspy.refactor_imports-3.0.2-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
classify-importsParses, classifies, and sorts Python import…
permissive · top 15,000 on PyPI
isortisort sorts Python imports alphabetically and…
permissive · top 1,000 on PyPI
reorder-python-importsAutomatically reorders Python imports into a…
permissive · top 15,000 on PyPI
usortμsort sorts Python imports within detected…
permissive · top 5,000 on PyPI
import-depsAnalyzes Python module imports statically using…
permissive · top 5,000 on PyPI
stdlib-listProvides lists of Python standard library…
permissive · top 5,000 on PyPI
flake8-tidy-importsA flake8 plugin that detects and reports…
permissive · top 15,000 on PyPI
attributes-docExtracts and stores docstrings for class…
permissive · top 15,000 on PyPI
ipynbImports Jupyter Notebook (.ipynb) files as…
permissive · top 15,000 on PyPI
ropeRope is a Python refactoring library that…
copyleft · top 5,000 on PyPI