Skip to main content

Trustworthy diagnostics for Python imports.

Project description

importlens

importlens is a Python library and CLI for trustworthy diagnostics of Python imports.

The current v1 candidate is built to help developers inspect import-time cost, internal import structure, and circular dependencies without overstating certainty or acting like an automatic optimizer.

Problem

Python import issues are easy to feel and hard to inspect.

  • CLI tools can feel slow without a clear picture of which imports dominate startup.
  • Applications can accumulate tangled internal modules that make import cycles and fragile package structure harder to reason about.
  • Raw profiling output exists, but it is hard to connect to package architecture and harder to trust without clear labeling.

importlens aims to combine measured runtime timing with approximate static graph analysis in a way that stays honest about what is known, what is inferred, and what remains uncertain.

Scope

V1 is intentionally small.

  • profile: runtime import-time diagnostics for a local target
  • graph: static import graph analysis for a local package or path
  • cycles: cycle detection from the inferred static graph
  • report: a combined human-readable or JSON summary

V1 will not include dashboards, IDE integration, auto-fixes, or deep support for dynamic import systems.

Current Status

Observed in this workspace:

  • the current test suite passes locally (49 passed on the latest rerun)
  • real-repo hardening runs completed against the pinned validation repositories
  • graph and cycles are currently the strongest commands on real package targets
  • profile and report remain more environment-sensitive on dependency-heavy repos

This means importlens is already credible as a static diagnostics tool, while the runtime-facing commands should still be treated as narrower and more environment-sensitive.

Installation

For standard use:

pip install importlens

For development and local testing:

python -m venv .venv
.venv\Scripts\activate
pip install -e .[dev]

Commands

importlens graph src/my_package
importlens cycles src/my_package
importlens profile app.py
importlens report app.py

Accepted target forms:

  • local script paths such as app.py
  • local package directories such as src/my_package
  • local module targets such as pkg.module when they can be resolved locally

Example Output

Static graph analysis on a real package target:

importlens graph
target: ...\validation_repos\requests\src\requests
target_type: package
node_count: 18
edge_count: 304
limitations:
- Some imports could not be resolved statically and are reported as unresolved.

Cycle detection on the same target:

importlens cycles
target: ...\validation_repos\requests\src\requests
target_type: package
cycles:
- no cycles found

Runtime profiling on dependency-heavy repos currently fails honestly when the active environment cannot import the target:

error: Runtime profiling failed: ...
ModuleNotFoundError: No module named 'urllib3'

That failure mode is intentional product behavior for v1: importlens does not pretend a runtime profile succeeded when the target cannot actually import.

Validation

The repository includes:

CLI Target Forms

Accepted target forms for v1 are locked down early so command behavior stays testable:

  • local script path, for example app.py
  • local package directory, for example src/my_package
  • local module target when it can be resolved reliably, for example pkg.module

The CLI should reject:

  • URLs
  • non-Python files
  • missing paths
  • ambiguous targets that cannot be resolved cleanly

Known Limitations

  • Runtime timing is environment-dependent and should not be treated as a stable benchmark.
  • Static graph analysis is approximate and will not fully model dynamic imports or plugin loading.
  • Runtime-facing commands currently depend on the target's import environment being available.
  • report currently supports script and module targets only; package-directory report support is intentionally deferred until runtime profiling support catches up.

For the current support matrix and empirical hardening results, see KNOWN_LIMITATIONS.md and REAL_REPO_HARDENING.md.

License

importlens is licensed under the MIT License. See LICENSE for details.

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

importlens-0.1.1.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

importlens-0.1.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file importlens-0.1.1.tar.gz.

File metadata

  • Download URL: importlens-0.1.1.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for importlens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c29e37e72c6b7d170ab1ba35f9b22e4ea7010da9095fa2cb4dd04e85c09d61fa
MD5 16b5d740514ca721835f694a4698e6be
BLAKE2b-256 f7d8de40f2248787602d5f8d1148e59b4059ff788f0504ed2ccfe822402b2741

See more details on using hashes here.

Provenance

The following attestation bundles were made for importlens-0.1.1.tar.gz:

Publisher: ci.yml on HarshNsingh001/importlens

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

File details

Details for the file importlens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: importlens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for importlens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a89cbaaa79ff8054085fd24ee79bdf378279516e36c97fa168ff7707ede526a1
MD5 236229da787bf4120f5e94e56b5ea6be
BLAKE2b-256 6c547e6f451c36a685b4c5cb4ad4a4f397da71b10657c4e4bb845b719c9e0703

See more details on using hashes here.

Provenance

The following attestation bundles were made for importlens-0.1.1-py3-none-any.whl:

Publisher: ci.yml on HarshNsingh001/importlens

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