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 targetgraph: static import graph analysis for a local package or pathcycles: cycle detection from the inferred static graphreport: 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 passedon the latest rerun) - real-repo hardening runs completed against the pinned validation repositories
graphandcyclesare currently the strongest commands on real package targetsprofileandreportremain 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.modulewhen 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:
- a product brief in PRODUCT_BRIEF.md
- a design specification in DESIGN_SPEC.md
- fixture packages under
tests/fixtures/ - command, analysis, and report tests under
tests/ - a real-repo hardening report in REAL_REPO_HARDENING.md
- hardening notes in PHASE7_HARDENING_NOTE.md
- explicit support boundaries in KNOWN_LIMITATIONS.md
- an architecture walkthrough in ARCHITECTURE.md
- an engineering decisions note in ENGINEERING_DECISIONS.md
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.
reportcurrently 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28a586878ca5248525609babfa36104e1f0b1e90cccdf473e6ad876da1ca5891
|
|
| MD5 |
122dac611735f19185c147432e051dd5
|
|
| BLAKE2b-256 |
b69c03937b5cfa49c8b5c42d193deb6f7d6543072a90c9f87a90e71f4491c638
|
Provenance
The following attestation bundles were made for importlens-0.1.0.tar.gz:
Publisher:
ci.yml on HarshNsingh001/importlens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
importlens-0.1.0.tar.gz -
Subject digest:
28a586878ca5248525609babfa36104e1f0b1e90cccdf473e6ad876da1ca5891 - Sigstore transparency entry: 1155422375
- Sigstore integration time:
-
Permalink:
HarshNsingh001/importlens@c3743274d6a435661af0f2701f89fd01864350cb -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/HarshNsingh001
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@c3743274d6a435661af0f2701f89fd01864350cb -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36c309311b182df03ce588e4a0618d555d03beaed224469f7a979f58a8d71a21
|
|
| MD5 |
bee73032361e93658be3e4657dec666d
|
|
| BLAKE2b-256 |
63014a2374f98dd2dbbe344b276147951bcf9ebefda33bc3c9b02158b1e3007c
|
Provenance
The following attestation bundles were made for importlens-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on HarshNsingh001/importlens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
importlens-0.1.0-py3-none-any.whl -
Subject digest:
36c309311b182df03ce588e4a0618d555d03beaed224469f7a979f58a8d71a21 - Sigstore transparency entry: 1155422378
- Sigstore integration time:
-
Permalink:
HarshNsingh001/importlens@c3743274d6a435661af0f2701f89fd01864350cb -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/HarshNsingh001
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@c3743274d6a435661af0f2701f89fd01864350cb -
Trigger Event:
release
-
Statement type: