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.11.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.11-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pimporter-0.1.11.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.11.tar.gz
Algorithm Hash digest
SHA256 a682f378ce91bbb8dcacec15a417e06babab33cf956638a058b568f3b86c2e1e
MD5 c778f9fb1e6b3854bd867412da925da5
BLAKE2b-256 b8f81a0c3e4912dc27d6f5514b4730a5aaec6962fe61f0c9cfd1f1bb4b77c6c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pimporter-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 940ccd24bbbe7a723951cb6a1bd75ac3473f81539f09a0e9965c670ff436bb60
MD5 312c433135bb85c3f8d5a218d8098525
BLAKE2b-256 27c6d9931688edb9537c05d1fa1072ab2e53f25e39324331a1b04b7f25517280

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