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.2.tar.gz (18.5 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.2-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: importless-0.1.2.tar.gz
  • Upload date:
  • Size: 18.5 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.2.tar.gz
Algorithm Hash digest
SHA256 14e6bcc792adf5c7aa643bfcfb70d561446fbd232639dfbfc9fe1dc849913ca2
MD5 f0a909ae381fff17d3899aa1180d2de1
BLAKE2b-256 7df0c555b22c40c550ee254e6ceffef157342f00cf3f724fafc724e4762403f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: importless-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 62b73b4dc4bd27209590ea09440453b714c913a4e8d90a43d5a78c4f3ab147b7
MD5 47cfe1758e052f136299b6bdd090f86a
BLAKE2b-256 8c658043bef99b446a3d3d4e40eae890097299ef5779b2b9cb6669c162fed57d

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