🔍 importlens
See exactly what your imports are doing — unused, missing, and circular import detection using Python's AST.
🤔 Why importlens?
Unused imports slow down startup time, confuse readers, and clutter code. Missing entries in requirements.txt break other people's installs. Circular imports cause cryptic runtime errors.
importlens catches all three — using Python's own ast module, no external dependencies needed.
importlens scan ./myproject
📄 api.py
🔴 unused line 1 import json
🔴 unused line 3 requests
📄 utils.py
🔴 unused line 2 pathlib.Path as p
🟡 Packages used but not in requirements.txt:
❌ httpx
🔄 Circular imports detected:
🔄 models.py → db.py → models.py
──────────────────────────────────────────────────
📊 Scanned 8 file(s) | 34 import(s) | 3 unused
📦 Installation
pip install importlens
🚀 Usage
CLI
# Scan current directory
importlens scan .
# Scan a specific folder
importlens scan ./myproject
# Scan a single file
importlens scan app.py
# Skip certain checks
importlens scan . --no-circular
importlens scan . --no-unused
importlens scan . --no-missing
# Specify requirements file
importlens scan . --req requirements-dev.txt
Library
from importlens import scan_file, scan_directory
# Scan a single file
report = scan_file("app.py")
print(report.imports) # all imports
print(report.unused) # unused imports
print(report.used) # used imports
# Scan a whole directory
reports = scan_directory("./myproject")
for report in reports:
if report.unused:
print(f"{report.filepath}: {len(report.unused)} unused imports")
🔍 What importlens detects
import os # ✅ detects
import numpy as np # ✅ detects alias
from pathlib import Path # ✅ detects
from os.path import join as pj # ✅ detects alias
from typing import List, Dict # ✅ detects multiple
🆚 importlens vs flake8/pylint
| Feature | importlens | flake8 | pylint |
|---|---|---|---|
| Unused imports | ✅ | ✅ | ✅ |
| Circular imports | ✅ | ❌ | ✅ |
| Missing in requirements.txt | ✅ | ❌ | ❌ |
| Zero dependencies | ✅ | ❌ | ❌ |
| Beginner-friendly output | ✅ | ⚠️ | ⚠️ |
🧪 Running Tests
pip install pytest
pytest tests/ -v
📄 License
MIT — free to use in personal and commercial projects.
Metadata
Release files for importlens-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| importlens_py-0.1.0.tar.gz | 11.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| importlens_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / importlens_py-0.1.0.tar.gz
| Download URL | importlens_py-0.1.0.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a8256d1d504b468077d43d84249cb5cf2b4465cb2b90e0020b5a46d5da9c0ca
|
|
BLAKE2b-256 checksum How to use checksums |
0ea9c467fe00529302bcd27efeca143a6941977745a5c508413bb1b9cdc25bae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / importlens_py-0.1.0-py3-none-any.whl
| Download URL | importlens_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b0d076c4a8961e5772838558522c6602dfaf630dab766bc69793b3554bb72b0
|
|
BLAKE2b-256 checksum How to use checksums |
0d089fc795f6c370f87a68d42ba2035cc4a6f803ca9ce6fb14b172e36c33fa3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|