Skip to main content

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.

PyPI version Tests License: MIT Python 3.10+

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 --src to add extra directories to sys.path
  • Noise-free — only reports ImportError / ModuleNotFoundError; ignores runtime exceptions
  • Auto-skips virtual environments (.venv, venv) and build artefacts
  • CI-friendly — exits with code 1 on any broken import, 0 on 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

Ajoutez ceci à votre fichier .pre-commit-config.yaml :

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/matthieugraziani/py-import-checker
    rev: v0.1.0
    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 utilise importlib.util.spec_from_file_location pour charger chaque fichier .py dans un namespace isolé. Seules les erreurs d’import sont capturées — tout le reste (erreurs runtime, variables manquantes, etc.) est ignoré.

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.1.0 ou 0.2.0) :
   ```bash
   hatch build
   hatch publish

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_import_checker-0.2.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_import_checker-0.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file py_import_checker-0.2.0.tar.gz.

File metadata

  • Download URL: py_import_checker-0.2.0.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

Hashes for py_import_checker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 84fd9395d88b2bcda825d883b58f7ee99cdabcd0c96f0cb4c1aa30a222b4c321
MD5 0c3ed6118dcefbc648dffbf838f76bd6
BLAKE2b-256 df33ab8e9031e3edda8f6a603f36de4bebbad70f812d6d20c348c72130c746f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_import_checker-0.2.0.tar.gz:

Publisher: publish.yml on matthieugraziani/py-import-checker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_import_checker-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_import_checker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6eaf960918443074c54a5f762e874c0c2fbafa21ab667bf2ecaef0d7f9bf7795
MD5 313cf8aeba8670d678afc2f2c655c614
BLAKE2b-256 80da2343f775c25dda5d808293863c4893ed30650a2f9c4e5dd1f12405222c6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_import_checker-0.2.0-py3-none-any.whl:

Publisher: publish.yml on matthieugraziani/py-import-checker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page