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

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


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.3.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.3-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

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

Hashes for py_import_checker-0.2.3.tar.gz
Algorithm Hash digest
SHA256 384d880e0ac3cb0daf71732699111c657ee26421d71cce4f9b9da0f8b2a5d2b4
MD5 9e4d2494ca73709a4e8e08453f6c5645
BLAKE2b-256 8bf576a0cb12d9d0389c95ea78bdffa8c44d68804638931754fd52a7939e9dc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_import_checker-0.2.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for py_import_checker-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6f2fdebe395317445f5d5d7cdf879eff8ae94c1d4f1d0a3941ecbe01da2653b7
MD5 74648c26b5b84111bbf50a500faef06d
BLAKE2b-256 b00f5cc365884389d176c7f74a2640112986dd71c617a378d5bea62d577c3f0f

See more details on using hashes here.

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

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