# ImportNinja

![Build Status](https://github.com/linustg/ImportNinja/actions/workflows/python-app.yml/badge.svg)
![PyPI version](https://badge.fury.io/py/ImportNinja.svg)
![License](https://img.shields.io/badge/license-MIT-blue.svg)

**ImportNinja** is a Python CLI tool designed to scan your projects for dependencies, detect unused imports, and help keep your `requirements.txt` file clean and up-to-date. Simplify your dependency management with lightning-fast scans and detailed reports.

---

## Features

- **Recursive Scanning**: Scans all `.py` files in your project.
- **Detects Unused Imports**: Identifies libraries that are imported but never used.
- **Requirements Analysis**: Checks if your `requirements.txt` is up to date.
- **Automatic Updates**: Optionally writes missing dependencies to `requirements.txt`.
- **Fast & Lightweight**: Built using Python's `ast` for efficient parsing.

---

## Installation

Install ImportNinja directly from PyPI:

```bash
pip install ImportNinja
```

---

## Usage

### Basic Command

```bash
import-ninja /path/to/your/project
```

This will scan the project directory and list all detected dependencies and unused imports.

### With Requirements File

```bash
import-ninja /path/to/your/project -r requirements.txt
```

- **`-r` or `--requirements`**: Specify the `requirements.txt` file to compare with detected imports. ImportNinja will analyze and suggest updates.

### Example Output

```
Scanning for imports...
Total Python Files Scanned: 6
Total Import Statements: 9
Unique Libraries Imported: 8
Total Unused Imports: 6

Unused Imports:
- setup.py:
  - setuptools
- ImportNinja\analyzer.py:
  - pathlib
- ImportNinja\cli.py:
  - ImportNinja.scanner
  - ImportNinja.utils
  - ImportNinja.analyzer
- ImportNinja\scanner.py:
  - pathlib

Requirements file analysis:

Imports missing in requirements.txt:
- sys
- ast
- argparse
- pathlib

Dependencies:
- argparse
- ast
- pathlib
- setuptools
- sys

Requirements saved to requirements.txt
```

---

## Contributing

We welcome contributions! To get started:

1. Fork the repository.
2. Create a new branch: `git checkout -b feature/your-feature-name`.
3. Make your changes.
4. Run tests to ensure everything works.
5. Submit a pull request!

---

## License

This project is licensed under the [MIT License](LICENSE).

---

## Links

- **PyPI**: [https://pypi.org/project/ImportNinja/](https://pypi.org/project/ImportNinja/)
- **GitHub**: [https://github.com/linustg/ImportNinja](https://github.com/linustg/ImportNinja)

---

## Contact

For questions or support, feel free to reach out:

[GitHub](https://github.com/linustg)
