Fast, zero-dependency Python import health scanner
Project description
py-import-checker
Fast, zero-dependency Python import health scanner.
Recursively scan any Python project and instantly surface every broken or missing import — before your tests run, before CI fails, before runtime surprises you.
py-import-checker src/ --src src/
py-import-checker — Python import health scanner
Scanning /home/user/myproject/src
──────────────────────────────────────────────────
✗ mypackage/broken_module.py
ModuleNotFoundError: No module named 'nonexistent_lib'
──────────────────────────────────────────────────
✗ 1 broken import(s) found in 14 file(s) scanned.
Features
- Zero dependencies — uses only the Python standard library (
importlib,pathlib,sys) - src-layout aware — pass
--srcto add extra directories tosys.path - Noise-free — only reports
ImportError/ModuleNotFoundError; ignores runtime exceptions - Auto-skips virtual environments (
.venv,venv) and build artefacts - CI-friendly — exits with code
1on any broken import,0on success - Self-checking — the CI pipeline scans itself with
py-import-checker
Installation
pip install py-import-checker
Or install from source (editable):
git clone https://github.com/matthieugraziani/py-import-checker
cd py-import-checker
pip install -e .
Usage
Command line
# Scan the current directory
py-import-checker
# Scan a specific directory
py-import-checker path/to/project
# src-layout project (adds src/ to sys.path)
py-import-checker . --src src/
# Multiple extra paths
py-import-checker . --src src/ --src lib/
# Custom file glob
py-import-checker . --glob "app/**/*.py"
# Verbose output (show all files, not just errors)
py-import-checker . -v
Python API
from pathlib import Path
from py_import_checker.checker import check_directory
result = check_directory(
root=Path("src/"),
extra_paths=[Path("src/")],
)
if not result.success:
for err in result.errors:
print(f"{err.file}: {err.error_type}: {err.message}")
Pre-commit hook
Add this to your .pre-commit-config.yaml:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/matthieugraziani/py-import-checker
rev: v0.2.2
hooks:
- id: py-import-checker
args: [--src, src/]
GitHub Actions
- name: Check imports
run: |
pip install py-import-checker
py-import-checker . --src src/
How it works
py-import-checker uses importlib.util.spec_from_file_location to load each .py file in an isolated namespace. Only import errors are captured — everything else (runtime exceptions, missing variables, etc.) is ignored.
Roadmap (suggestions)
- Mode --fix (suggestions d’imports)
- Support des packages namespace (init.py moins strict)
- Intégration VS Code / LSP
- Rapport HTML / JSON
- Détection de circular imports (optionnel)
Development
# Install with dev extras
pip install -e ".[dev]"
# Run tests
pytest
# Lint
ruff check src/ tests/
# Type-check
mypy src/
License - MIT
Auteur : Matthieu Graziani
### Améliorations apportées
- En-tête centré + badges propres
- Démo plus visible
- Sections plus aérées
- Roadmap ajoutée (pour montrer l’évolution)
- Meilleure lisibilité
### Actions prioritaires maintenant
1. **Publier sur PyPI** (version 0.2.3) :
```bash
hatch build
hatch publish
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 py_import_checker-0.2.3.tar.gz.
File metadata
- Download URL: py_import_checker-0.2.3.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
384d880e0ac3cb0daf71732699111c657ee26421d71cce4f9b9da0f8b2a5d2b4
|
|
| MD5 |
9e4d2494ca73709a4e8e08453f6c5645
|
|
| BLAKE2b-256 |
8bf576a0cb12d9d0389c95ea78bdffa8c44d68804638931754fd52a7939e9dc0
|
Provenance
The following attestation bundles were made for py_import_checker-0.2.3.tar.gz:
Publisher:
publish.yml on matthieugraziani/py-import-checker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_import_checker-0.2.3.tar.gz -
Subject digest:
384d880e0ac3cb0daf71732699111c657ee26421d71cce4f9b9da0f8b2a5d2b4 - Sigstore transparency entry: 1818274636
- Sigstore integration time:
-
Permalink:
matthieugraziani/py-import-checker@2a868c7a25b045dc5b26502941530e75472d0b3a -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/matthieugraziani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2a868c7a25b045dc5b26502941530e75472d0b3a -
Trigger Event:
release
-
Statement type:
File details
Details for the file py_import_checker-0.2.3-py3-none-any.whl.
File metadata
- Download URL: py_import_checker-0.2.3-py3-none-any.whl
- Upload date:
- Size: 7.1 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 |
6f2fdebe395317445f5d5d7cdf879eff8ae94c1d4f1d0a3941ecbe01da2653b7
|
|
| MD5 |
74648c26b5b84111bbf50a500faef06d
|
|
| BLAKE2b-256 |
b00f5cc365884389d176c7f74a2640112986dd71c617a378d5bea62d577c3f0f
|
Provenance
The following attestation bundles were made for py_import_checker-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on matthieugraziani/py-import-checker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_import_checker-0.2.3-py3-none-any.whl -
Subject digest:
6f2fdebe395317445f5d5d7cdf879eff8ae94c1d4f1d0a3941ecbe01da2653b7 - Sigstore transparency entry: 1818274639
- Sigstore integration time:
-
Permalink:
matthieugraziani/py-import-checker@2a868c7a25b045dc5b26502941530e75472d0b3a -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/matthieugraziani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2a868c7a25b045dc5b26502941530e75472d0b3a -
Trigger Event:
release
-
Statement type: