Detect and repair broken Python imports after refactoring, with zero runtime cost
Project description
import-mend
Detect and repair broken Python imports after refactoring — with zero runtime cost.
What it does
After a codebase refactoring (manual or autonomous), module paths shift. Every file that
imported moved symbols now references a path that no longer exists. import-mend fixes
this retroactively:
- Inventories symbols before and after using git history + AST (no code executed)
- Detects moves, renames, splits, and merges in the migration map
- Rewrites all broken imports in-place using
libcst(format-preserving) - Verifies every import via filesystem + AST checks (zero runtime loading)
Installation
pip install import-mend
Usage
# Full pipeline: fix then verify
python -m import_mend run
# Fix broken imports only
python -m import_mend fix
# Verify imports only (CI gate)
python -m import_mend check
# With options
python -m import_mend run \
--source-dirs src lib \
--git-ref HEAD~3 \
--format json \
--log-level DEBUG
Programmatic API
from import_mend import fix, check, run
# Full pipeline
result = run(root="/path/to/project", source_dirs=["src"], git_ref="HEAD~1")
# Fix only
fix_results = fix(root=".", git_ref="abc123")
# Check only
errors = check(root=".", encapsulation_check=True)
Configuration
Add to pyproject.toml:
[tool.import_mend]
source_dirs = ["src", "lib"]
exclude_patterns = [".venv", "__pycache__", "node_modules"]
git_ref = "HEAD"
encapsulation_check = true
output_format = "human" # or "json"
log_level = "INFO" # or "DEBUG", "ERROR"
check_stubs = true # .pyi stub fallback
check_getattr = true # __getattr__ suppression
Design
- Deterministic-first: AST-based analysis handles the common case. LLM integration for residuals is out of scope — the structured error list is the handoff contract.
- Zero runtime cost: The checker never loads a module. Safe in any environment.
- Generic: Works on any Python project with git. No project-specific config required.
- Single dependency: Only
libcstbeyond the standard library.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file import_mend-0.1.1.tar.gz.
File metadata
- Download URL: import_mend-0.1.1.tar.gz
- Upload date:
- Size: 47.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6d1e4c87a6415768794dbafaf8f8b83990ef9bdbe1159c8150f6e69062d3896
|
|
| MD5 |
e1c383928626e1f9c47ab8e2a5edfb74
|
|
| BLAKE2b-256 |
a4baf630b28a80f03644c0ad599c1b4286b047ab3c600f9ddd14f003c6856caf
|
Provenance
The following attestation bundles were made for import_mend-0.1.1.tar.gz:
Publisher:
publish.yml on JuanSync7/import-mend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
import_mend-0.1.1.tar.gz -
Subject digest:
c6d1e4c87a6415768794dbafaf8f8b83990ef9bdbe1159c8150f6e69062d3896 - Sigstore transparency entry: 1279027380
- Sigstore integration time:
-
Permalink:
JuanSync7/import-mend@b51713442f2c884ea42b47c011b8ea3dfd280671 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/JuanSync7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b51713442f2c884ea42b47c011b8ea3dfd280671 -
Trigger Event:
push
-
Statement type:
File details
Details for the file import_mend-0.1.1-py3-none-any.whl.
File metadata
- Download URL: import_mend-0.1.1-py3-none-any.whl
- Upload date:
- Size: 30.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a815250e8831923dded50a1511f71283d012278479b92592cc223a30cf3b5919
|
|
| MD5 |
7df9622f55ef0b21c91137484ed11404
|
|
| BLAKE2b-256 |
d828ae0ae7dee493e386b12bfb270358ca7ccfe44e5069af78ce790327911ab0
|
Provenance
The following attestation bundles were made for import_mend-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on JuanSync7/import-mend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
import_mend-0.1.1-py3-none-any.whl -
Subject digest:
a815250e8831923dded50a1511f71283d012278479b92592cc223a30cf3b5919 - Sigstore transparency entry: 1279027434
- Sigstore integration time:
-
Permalink:
JuanSync7/import-mend@b51713442f2c884ea42b47c011b8ea3dfd280671 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/JuanSync7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b51713442f2c884ea42b47c011b8ea3dfd280671 -
Trigger Event:
push
-
Statement type: