Skip to main content

Checks for conflicting, unused or duplicate import aliases

Project description

pimporter 🐍📦

Clean up your code's cargo.

PyPI version License: MIT Downloads

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.dev0.tar.gz (9.8 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.dev0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pimporter-0.1.10.dev0.tar.gz
  • Upload date:
  • Size: 9.8 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.dev0.tar.gz
Algorithm Hash digest
SHA256 7df2554e99d0ed4176af3040de983d13ed030b6ec120d963f7c7dad9e4a6eace
MD5 15a123ef718b604115bc473652c57822
BLAKE2b-256 fa99d26c9fc21735ca214f50db20b335062361404389b98a58bb862ff15aa43e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pimporter-0.1.10.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 91e43f40d219093ca7ca9557719380e8b3f45f55fb6754bda1219a507d31389e
MD5 5d782b2e253060f1539dd7f65199946c
BLAKE2b-256 8631335cfd2a91ea43a61ccb73347950396da5656b85a1d1a5509d0760600b38

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