Skip to main content

Checks for conflicting, unused or duplicate import aliases

Project description

pimporter 🐍📦

Clean up your code's cargo.

pimporter is a lightweight static analysis tool for inspecting and cleaning up Python import statements.

It helps identify and summarize issues such as:

  • Aliases (as) used for multiple modules (conflicts)
  • Duplicate or hidden import aliases
  • Unused imports
  • Local vs external imports
  • Clean summary per file

🔧 Installation

Install via pip (after packaging it as a wheel or locally):

pip install pimporter

Or from a local directory:

pip install .

🚀 Usage

pimporter path/to/your/script_or_directory.py
  • You can pass either a single Python file or a directory (recursively scans .py files).
  • The tool will display detailed line-by-line output with color-coded status.

🖨️ Example Output

>>> Scanning 11 Python files in 'StockBot'...
 
  gui/main_window.py

  [!!!] Conflict: Alias 'foo' is used for multiple modules:
    Line 10   -> bar as foo
    Line 18   -> foo1 as foo1
    Line 31   -> module_a.foo as foo
  
(...)
    
    Line    6 - [OK]   used                 QTabWidget from PySide6.QtWidgets.QTabWidget
    Line    6 - [!]    duplicate (1)        QWidget from PySide6.QtWidgets.QWidget
    Line    6 - [OK]   used                 QVBoxLayout from PySide6.QtWidgets.QVBoxLayout
    Line    6 - [!]    duplicate (5)        QWidget from PySide6.QtWidgets.QWidget
(...)
    Line   10 - [!!!]  unused & duplicate   foo from bar  [conflict !!!]
    Line   11 - [!!]   unused               QPointF from PySide6.QtCore.QPointF

(...)
    ________________________________________________________________________________
    Line   27 - [!]    hidden duplicate     bups from PySide6.QtWidgets.QWidget
        |  Full name: PySide6.QtWidgets.QWidget -> imported here as: bups
        |    also imported PySide6.QtWidgets.QWidget in Line 6 as QWidget
        |    also imported PySide6.QtWidgets.QWidget in Line 6 as QWidget
        |    also imported PySide6.QtWidgets.QWidget in Line 6 as QWidget
(...)

Detected Import Summary:
L4  from PySide6.QtGui import QPalette, QColor
L6  from PySide6.QtWidgets import (QWidget,
    QMainWindow, QTabWidget, QWidget, QVBoxLayout, QLabel, QComboBox, QWidget,
    QHBoxLayout, QWidget, QWidget, QWidget)
L10 import bar as foo 
L11 from PySide6.QtCore import Qt, QTimer, QPointF, Signal
L12 from PySide6.QtWebEngineWidgets import QWebEngineView

(...)

 Summary of Analysis:
                                             Used    Hidden   Regular    Unused        Unused
 Datei                           Total Used Local Duplicate Duplicate Duplicate Unused  Local
 ============================================================================================
 file1.py                           12    5     4         0         0         0      3      0
 file2.py                            3    3     0         0         0         0      0      0
 main.py                            23    9     1         1         5         3      3      2

✅ Features

  • Detects alias conflicts across imports
  • Highlights hidden and explicit duplicates
  • Shows unused modules
  • Differentiates between local and external modules
  • Colorized terminal output
  • File-by-file detailed outputs
  • Summary in original formatting
  • Overall summary of all scanned files
  • (Planned) Automatic fixing of duplicates
  • (Planned) CLI arguments for filtering and exporting

📦 Dependencies

  • colorama – for colorful terminal output

💡 Motivation

While linters like pylint, flake8, or ruff cover general import cleanliness, pimporter focuses specifically on the integrity and clarity of alias usage – particularly useful for larger codebases or shared projects where import patterns can become inconsistent or ambiguous.


🧪 Development

Clone and run:

python -m pimporter path/to/codebase/

or

pimporter path/to/codebase/

or

pimporter

📄 License

MIT License – use it, modify it, share it.


✍️ Author

Your Name optional.email@example.com

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

pimporter-0.1.10.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

pimporter-0.1.10-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pimporter-0.1.10.tar.gz.

File metadata

  • Download URL: pimporter-0.1.10.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.6

File hashes

Hashes for pimporter-0.1.10.tar.gz
Algorithm Hash digest
SHA256 67806058e270f058c4e9077f42bab33a9adefba49e2022c00ad4e893b9695e11
MD5 aec441796dbebc3ce2f45e0332584312
BLAKE2b-256 6cb2327356b972fe481d0cd78a01246d30c282ce7ab4b30f13404eb21309ecc0

See more details on using hashes here.

File details

Details for the file pimporter-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: pimporter-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.6

File hashes

Hashes for pimporter-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 2828fe03dfaaec11cb712d64977df1332eab7b13db73c799ec6506b920d0ae16
MD5 58c55eda443fccacaad0258b11519484
BLAKE2b-256 504fe60308dea42347246fde7039a769910746af8a06302d083017d0b176b966

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