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

python -m venv .venv
.venv\Scripts\python -m 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.0.tar.gz (21.4 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.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: importlens-0.1.0.tar.gz
  • Upload date:
  • Size: 21.4 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.0.tar.gz
Algorithm Hash digest
SHA256 28a586878ca5248525609babfa36104e1f0b1e90cccdf473e6ad876da1ca5891
MD5 122dac611735f19185c147432e051dd5
BLAKE2b-256 b69c03937b5cfa49c8b5c42d193deb6f7d6543072a90c9f87a90e71f4491c638

See more details on using hashes here.

Provenance

The following attestation bundles were made for importlens-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: importlens-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36c309311b182df03ce588e4a0618d555d03beaed224469f7a979f58a8d71a21
MD5 bee73032361e93658be3e4657dec666d
BLAKE2b-256 63014a2374f98dd2dbbe344b276147951bcf9ebefda33bc3c9b02158b1e3007c

See more details on using hashes here.

Provenance

The following attestation bundles were made for importlens-0.1.0-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