See exactly what your imports are doing โ unused, missing, and circular import detection.
Project description
๐ 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.
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_py-0.1.0.tar.gz.
File metadata
- Download URL: importlens_py-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a8256d1d504b468077d43d84249cb5cf2b4465cb2b90e0020b5a46d5da9c0ca
|
|
| MD5 |
7df441128dbff4aeeee8ffefaab5bcf4
|
|
| BLAKE2b-256 |
0ea9c467fe00529302bcd27efeca143a6941977745a5c508413bb1b9cdc25bae
|
File details
Details for the file importlens_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: importlens_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b0d076c4a8961e5772838558522c6602dfaf630dab766bc69793b3554bb72b0
|
|
| MD5 |
e75b7f6b733981528e3423cfaf6332c8
|
|
| BLAKE2b-256 |
0d089fc795f6c370f87a68d42ba2035cc4a6f803ca9ce6fb14b172e36c33fa3b
|