Skip to main content

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.

Python 3.8+ License: MIT


๐Ÿค” 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

importlens_py-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

importlens_py-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

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

Hashes for importlens_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2a8256d1d504b468077d43d84249cb5cf2b4465cb2b90e0020b5a46d5da9c0ca
MD5 7df441128dbff4aeeee8ffefaab5bcf4
BLAKE2b-256 0ea9c467fe00529302bcd27efeca143a6941977745a5c508413bb1b9cdc25bae

See more details on using hashes here.

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

Hashes for importlens_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b0d076c4a8961e5772838558522c6602dfaf630dab766bc69793b3554bb72b0
MD5 e75b7f6b733981528e3423cfaf6332c8
BLAKE2b-256 0d089fc795f6c370f87a68d42ba2035cc4a6f803ca9ce6fb14b172e36c33fa3b

See more details on using hashes here.

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