Skip to main content

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.

Metadata

Release files for importlens 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for importlens 0.1.1
File Size Uploaded Provenance Actions
importlens-0.1.1.tar.gz 21.5 kB With provenance Details for importlens-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for importlens 0.1.1
File Interpreter ABI Platform Actions
importlens-0.1.1-py3-none-any.whl Python 3 none any Details for importlens-0.1.1-py3-none-any.whl

Total release size: 38.9 kB

Release files / importlens-0.1.1.tar.gz

Download URL importlens-0.1.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c29e37e72c6b7d170ab1ba35f9b22e4ea7010da9095fa2cb4dd04e85c09d61fa
BLAKE2b-256 checksum
How to use checksums
f7d8de40f2248787602d5f8d1148e59b4059ff788f0504ed2ccfe822402b2741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

Release files / importlens-0.1.1-py3-none-any.whl

Download URL importlens-0.1.1-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a89cbaaa79ff8054085fd24ee79bdf378279516e36c97fa168ff7707ede526a1
BLAKE2b-256 checksum
How to use checksums
6c547e6f451c36a685b4c5cb4ad4a4f397da71b10657c4e4bb845b719c9e0703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

Security for importlens 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for importlens-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page