Skip to main content

Deboalt your code by removing unused import statements

Project description

ImportLess

ImportLess is a command-line tool designed to help Python developers generate minimal dependency lists by analyzing the actual imports used in their source code. This makes your requirements.txt lean, accurate, and free from unused or redundant packages.


Table of Contents

  1. Why ImportLess?
  2. Features
  3. Installation
  4. Quick Start
  5. Command Reference
  6. How It Works
  7. Project Structure
  8. Contributing
  9. License
  10. Support

Why ImportLess?

Managing dependencies in Python projects can be tricky:

  • requirements.txt files often include packages no longer used.
  • Manual dependency tracking is error-prone and time-consuming.
  • Over-installed dependencies increase project size and complexity.

ImportLess automates this process by:

  • Scanning your Python files for actual import statements.
  • Filtering and identifying the exact packages your project depends on.
  • Helping you keep your dependency list minimal and up to date.

Features

  • Comprehensive scanning of Python source files in any directory.
  • Supports both top-level and detailed import listings.
  • CLI progress display with rich formatting using the rich library.
  • Configurable scanning delay to simulate progress or manage performance.
  • Clear, formatted output tables of detected imports.
  • Designed to be extensible and modular.

Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Install from PyPI

Simply run:

pip install importless

Install from Source

If you prefer the bleeding edge or want to contribute:

git clone https://github.com/yourusername/importless.git
cd importless
pip install -e .

This will install the package in editable mode so you can modify and test easily.


Quick Start

Navigate to your Python project directory, then run:

importless scan

This will scan the current directory and show the top-level imports detected.

To see all imports (including from from module import name style), use:

importless scan --all

If you want to slow down scanning to watch the progress bar more clearly (default delay is 0.05 seconds), specify the delay:

importless scan --delay 0.1

Command Reference

scan

Scans the specified directory for Python files and extracts import statements.

Arguments

  • path (optional): Directory path to scan. Defaults to the current directory (.).

Options

  • --all (flag): Show all imports instead of just top-level imports.
  • --delay FLOAT: Time delay (in seconds) between processing each file. Default is 0.05.

Examples

# Scan current directory, show top-level imports only
importless scan

# Scan a specific project directory, show all imports
importless scan --all ./myproject

# Scan with no delay for faster results
importless scan --delay 0

How It Works

  1. File Discovery: Uses filewalker utility to recursively find all .py files in the target directory.
  2. Source Parsing: Reads each Python file and analyzes it for import statements using the analyze_source core function.
  3. Import Extraction: Collects import details such as the module name, imported names, and aliases.
  4. Filtering: By default, only top-level imports (e.g., import module) are shown unless --all is specified.
  5. Presentation: Shows a nicely formatted table of imports using the rich library and prints summary messages.

Project Structure

importless/
├── cli/               # CLI commands implemented with Typer
├── core/              # Core logic for analyzing source and imports
├── models/            # Data models representing import nodes
├── utils/             # Utility functions (filewalker, formatting, etc.)
├── config.py          # Configuration handling
tests/                  # Unit and integration tests
examples/               # Sample projects to try ImportLess
scripts/                # Helper scripts for development
docs/                   # Documentation files

Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository on GitHub and clone it locally.

  2. Set up your environment:

    python -m venv venv
    source venv/bin/activate   # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
    
  3. Make your changes.

  4. Write tests for new features or bug fixes.

  5. Run tests with pytest to ensure nothing is broken:

    pytest
    
  6. Format your code using black:

    black .
    
  7. Commit your changes with clear messages.

  8. Submit a pull request describing your improvements.


License

ImportLess is licensed under the MIT License.


Support

If you encounter any issues or have questions, please:


Thank you for using ImportLess! Keep your Python projects clean and dependency-minimal.

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

importless-0.1.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

importless-0.1.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file importless-0.1.1.tar.gz.

File metadata

  • Download URL: importless-0.1.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for importless-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dbe0556f1fd39c501b4e8e7c57ff229898aaa94ee6462e45cdbf29d81277b7bb
MD5 bb1d5810cfa8ce0413c59279f4ab3e2c
BLAKE2b-256 451a6ecd4a68f2fbca7031cfa0ce82a4a01d0fb434ffe59f1c9e4a9e7e761ad8

See more details on using hashes here.

File details

Details for the file importless-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: importless-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for importless-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a28271c3806c368dfba2a3d4d7c2415ef7c4105d0575c6ca4ac27b647fe3ffca
MD5 fa7971574bb776b1356c9a8bb5cb2578
BLAKE2b-256 265b9b32f7a41d01ef287c3c64928530608bd131595b26e83324afd9cc8cb57c

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