Skip to main content

A smart tool to analyze, generate, and check Python project requirements.

Project description

Req-Scanner: The Smart Python Requirements Tool 🐍

PyPI version License: MIT

Req-Scanner is a powerful command-line tool designed to bring sanity to your Python project's dependencies. It analyzes your project's imports, compares them against your requirements.txt file, and helps you create a clean, minimal, and accurate list of dependencies.

Stop guessing which packages are really needed. Let req-scanner do the work for you.


What is Req-Scanner?

Manually managing a requirements.txt file is error-prone. You might forget to add a new import, leave behind unused packages, or miss a critical sub-dependency. Req-Scanner solves these problems by automating the analysis and validation process, ensuring your requirements file is always a perfect reflection of your project's actual needs.

It's built on a clear philosophy: distinguish between primary packages (what you directly import) and their dependencies (what they need to run). This allows for highly accurate and logical consistency checks.

Key Features

  • 🎯 Accurate Import Detection: Uses Python's Abstract Syntax Tree (ast) module to safely and precisely find all imported packages.
  • 🔍 Smart Dependency Analysis: Leverages pip's own resolver (via pip show) to accurately determine the real-world dependencies for your specific environment, correctly handling conditional and optional dependencies.
  • ✅ Comprehensive check Command: Validates your requirements.txt against 4 crucial, strict rules to ensure perfect consistency with your codebase.
  • ✨ Clean generate Command: Creates a flawless requirements.txt from scratch based on your project's actual imports, with optional inclusion of all transitive dependencies.
  • 🤖 CI/CD Friendly: Exits with a non-zero status code on critical errors, making it ideal for integration into automated workflows like GitHub Actions.

Installation

Install req-scanner directly from PyPI:

pip install req-scanner

Usage Guide

req-scanner has two main commands: generate and check. Both commands share the following options:

  • path: The path to your project directory (default: current directory).
  • --ignore: A space-separated list of file or directory patterns to ignore during the scan (e.g., venv "*.pyc").

1. generate: Create a Perfect Requirements File

Use the generate command to create a clean requirements.txt from scratch based on your project's actual usage. This is the perfect starting point for any project.

Command Signature:

req-scanner generate [path] [--output <filename>] [--include-deps] [--ignore <patterns...>]

Options:

  • --output <filename> or -o <filename>: The name of the file to be created (default: requirements.txt).
  • --include-deps: If specified, the output file will contain both the primary packages and all of their transitive dependencies. This is highly recommended for creating fully reproducible environments.

Examples:

# Generate a complete, reproducible file named requirements.txt
req-scanner generate . --include-deps

# Generate a file with only primary (directly imported) packages
req-scanner generate . -o minimal-reqs.txt

2. check: Verify Your Requirements File

Once you have a requirements.txt, the check command is your best friend for maintaining it. It audits your project based on 4 strict rules to find inconsistencies.

Command Signature:

req-scanner check [path] [--file <filename>] [--ignore <patterns...>]

Options:

  • --file <filename> or -f <filename>: Specifies the requirements file to check against (default: requirements.txt).

The 4 Rules of the check command:

  • ❌ Error (Rule 2: Primary Missing): Reports primary packages that are imported in your code but are missing from the requirements file.
  • ❌ Error (Rule 3: Dependency Missing): Reports primary packages that are present, but their own dependencies are missing from the file. It even shows the dependency path!
  • ❌ Error (Rule 4: Not Installed): Reports packages listed in the file that aren't actually installed in your virtual environment.
  • ⚠️ Warning (Rule 1: Unused Package): Warns about packages in the file that are never directly imported and are not dependencies of any other primary package.

Examples:

# Check the default requirements.txt in the current directory
req-scanner check .

# Check a different requirements file
req-scanner check . --file dev-requirements.txt

# Check a project in another folder, ignoring the 'build' directory
req-scanner check /path/to/project --ignore build

Contributing

Contributions are welcome! Please feel free to open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

req_scanner-0.2.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

req_scanner-0.2.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file req_scanner-0.2.1.tar.gz.

File metadata

  • Download URL: req_scanner-0.2.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for req_scanner-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a80e9707abf4f8dfdce81c84e5594e22d106b132a49e47b57ac425ce4ae95c54
MD5 6792e7084b3488849f50abb361359e5c
BLAKE2b-256 5d29a93f663b2d78dd1987740a10ca4199d6410b3a0a90f574ef55f52fcfc793

See more details on using hashes here.

File details

Details for the file req_scanner-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: req_scanner-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for req_scanner-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14aef85b22da391fb8bd5843bf09b8bdeaef2ea11a1d36b64e995577cafede78
MD5 12b9aaf8bc2658fd73751aa1ebcfbf4d
BLAKE2b-256 130609bcacf58c0100a4df79aaa427bf301616daed8e0260a63d5c02d753e72b

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