Skip to main content

py-import-checker

PyPI Downloads PyPI version Tests License: MIT Python 3.10+

A zero-dependency Python tool that scans a project and reports broken imports.

It loads Python files using the standard library and reports import failures before they reach runtime.

Features

  • Zero dependencies (Python standard library only)
  • Supports src/ layouts with --src
  • Reports ImportError and ModuleNotFoundError
  • Ignores runtime errors raised during module execution
  • Skips virtual environments and build directories
  • Works in CI with meaningful exit codes
  • Auto-fix broken imports with --fix (installs missing packages via pip)
  • Dry-run preview with --dry-run (shows what would be installed, no side-effects)

Installation

pip install py-import-checker

Usage

py-import-checker
py-import-checker path/to/project
py-import-checker . --src src/
py-import-checker . --src src/ --src lib/
py-import-checker . --glob "app/**/*.py"
py-import-checker . --verbose

Auto-fix

Install every missing package detected during the scan:

py-import-checker . --fix

Preview what would be installed without touching the environment:

py-import-checker . --dry-run

After a successful --fix, the tool re-scans automatically to confirm all imports are resolved.

Python API

from pathlib import Path

from py_import_checker.checker import check_directory

result = check_directory(
    Path("src"),
    extra_paths=[Path("src")],
)

if not result.success:
    for error in result.errors:
        print(error.file, error.message)

Pre-commit

repos:
  - repo: https://github.com/matthieugraziani/py-import-checker
    rev: v0.2.5
    hooks:
      - id: py-import-checker
        args: [--src, src/]

Development

pip install hatch
hatch env create
hatch run test
hatch run lint
hatch run type-check

License

MIT

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_import_checker-0.2.5.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.5.tar.gz
Algorithm Hash digest
SHA256 d5d88d448daa281650d84a783f6964fe2293d21b49bf55de642ec41e3afd7a3d
MD5 eccece8d3a3905472a4b8beabb133356
BLAKE2b-256 af14639e71666f3a35066eb41ee42c584484ff6330867a597549f70ac427dbaa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_import_checker-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e823c705fa5349702e67f027728ea3831e08b8cd1ce6e221b90cb16ce3ec541c
MD5 cae5d1f35c14ec88aec6f0fde236a894
BLAKE2b-256 c526c7c3c85eaed60069a4e0f93ffe60e4008867a6faf7422f6fb98e4d38695b

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_import_checker-0.2.5-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