Skip to main content

A lightweight Python linter for checking unused docstrings.

Project description

pymport

GitHub tag PyPI CI versions codecov license Linter: ruff

About

A lightweight Python linter for checking unused imports in your Python files.

Features

  • 🧹 Detects unused or shadowed imports that linters like ruff may miss
  • 🚫 Use noqa comments to ignore imports you want to keep
  • ⚙️ Minimalist CLI interface for easy integration in CI/CD pipelines
  • 🐍 No external dependencies beyond the Python standard library
  • 100% test coverage with automated tests

[!IMPORTANT] False positives

This tool is not possible to assure a 100% false positive free result due to the possible collateral execution effects when importing a module. This is, importing a module can affect or enable some feature needed somewhere else, so not using anything from that imported package/module does not necessarily mean is not needed.

A minimal typical example could be:

import os.path

print(os.curdir)

📦 Installation

To install pymport using pip, run the following command:

pip install pymport --upgrade

⚡ Quick Start

To run the linter on the current directory, use the following command:

pymport .
  • This will check all Python files in the current directory and its subdirectories.

Command-Line Interface

Usage: pymport [FILE] [--help] [--quiet] [--ignore=DIR]

Argument / Option Description
[FILE] Files or directories to lint. (Need at least one file or dir to check.)
[--help] Show help message and exit.
[--quiet] Decrease verbosity.
[--ignore] Directory basename to ignore. Can be used multiple times.

[!NOTE]

Option --ignore defaults to: .venv, .env, .git, .hg, .pytest_cache, .ruff_cache, __pycache__

[!TIP] Ignoring Unused Imports

Use a comment like # noqa: F401(or just # noqa) at the end of the import line to ignore specific unused imports.

Use same error code (F401) as Pyflakes, Ruff

Output

When unused imports are detected, they will be reported in the following format:

path/to/file.py:LINE-NUMBER: UNUSED-IMPORT-NAME

[!NOTE]

  • Exit code 0 means no unused imports were found; exit code 1 indicates that unused imports were detected.
  • When no unused imports are found, success message is printed, unless --quiet is used.

🛠️ Development

To contribute to the project, you can run the following commands for testing and documentation:

First, ensure you have the latest version of pip:

python -m pip install --upgrade pip

Running Tests

pip install --group=test --upgrade # Install test dependencies, skip if already installed
python -m pytest tests/ # Run all tests
python -m pytest tests/ --cov # Run tests with coverage

Running Linter

pip install --group=lint --upgrade  # Install lint dependencies, skip if already installed
ruff check . # Run linter

🗒️ License

This project is licensed under the MIT license.

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

pymport-0.0.4.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

pymport-0.0.4-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pymport-0.0.4.tar.gz.

File metadata

  • Download URL: pymport-0.0.4.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymport-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d28f8b531fdb70040419fe2f069391beccdd9278a5b22713991682350bd18020
MD5 c2592c5fe7ff2bb171dcde9dc177e77a
BLAKE2b-256 88d03b65dedef6bfbd81e8e290eb553f5c2ead4da9cd67dbf7af8ba6a75b1f0c

See more details on using hashes here.

File details

Details for the file pymport-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pymport-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymport-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 38d0146af6ef68ac89f164a2d7c152c8dcb510de0f2d7ee27250e9172e70989f
MD5 1f489140f4f789d94b375e6b111cd7b5
BLAKE2b-256 13f5a2ae27376ff5912d74cb075e7be4ef52eee1668dbfb2cd26a321c76e02ac

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