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
- Why ImportLess?
- Features
- Installation
- Quick Start
- Command Reference
- How It Works
- Project Structure
- Contributing
- License
- Support
Why ImportLess?
Managing dependencies in Python projects can be tricky:
requirements.txtfiles 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
richlibrary. - 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
pippackage 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 is0.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
- File Discovery: Uses
filewalkerutility to recursively find all.pyfiles in the target directory. - Source Parsing: Reads each Python file and analyzes it for import statements using the
analyze_sourcecore function. - Import Extraction: Collects import details such as the module name, imported names, and aliases.
- Filtering: By default, only top-level imports (e.g.,
import module) are shown unless--allis specified. - Presentation: Shows a nicely formatted table of imports using the
richlibrary 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:
-
Fork the repository on GitHub and clone it locally.
-
Set up your environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Make your changes.
-
Write tests for new features or bug fixes.
-
Run tests with
pytestto ensure nothing is broken:pytest
-
Format your code using
black:black . -
Commit your changes with clear messages.
-
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:
- Open an issue on the GitHub repository.
- Or reach out to the maintainers via email.
Thank you for using ImportLess! Keep your Python projects clean and dependency-minimal.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14e6bcc792adf5c7aa643bfcfb70d561446fbd232639dfbfc9fe1dc849913ca2
|
|
| MD5 |
f0a909ae381fff17d3899aa1180d2de1
|
|
| BLAKE2b-256 |
7df0c555b22c40c550ee254e6ceffef157342f00cf3f724fafc724e4762403f2
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62b73b4dc4bd27209590ea09440453b714c913a4e8d90a43d5a78c4f3ab147b7
|
|
| MD5 |
47cfe1758e052f136299b6bdd090f86a
|
|
| BLAKE2b-256 |
8c658043bef99b446a3d3d4e40eae890097299ef5779b2b9cb6669c162fed57d
|