yyds-pip-audit
yyds-pip-audit is a fast and precise CLI tool/library designed to audit Python package imports and map them to their corresponding PyPI distribution names and versions. It extracts import statements from source codes, filters out standard libraries and local project modules, and utilizes local Python environment package metadata to trace PyPI names.
It also supports checking your code imports against an existing requirements.txt to help you identify missing dependencies or unused packages.
✨ Features
- AST Parsing: Statically parses
.pyfiles using the Python Abstract Syntax Tree (AST) to reliably find all top-level imports. Files larger than 2MB are automatically skipped for performance. - Dynamic Import Scanning: Detects static string imports like
importlib.import_module('pandas')and__import__('numpy'). - Smart PyPI Mapping: Scans package metadata in your active python environment. Supports precise mapping of namespace packages (e.g.
google.cloud.storagemaps togoogle-cloud-storageand is displayed as such underImport Nameinstead of a vaguegoogle). - Clean Walk: Automatically ignores directories like
.venv,venv,node_modules,.git,.ideaas well as asset/data folders (data,dataset,static,media,assets,public,uploads,logs,tmp,temp,htmlcovetc.) to prevent directory traversal lag. - Auto
.gitignoreIntegration: Automatically parses and respects.gitignorerules in the target directory to skip matches out-of-the-box. pyproject.tomlSupport: Reads configuration settings from[tool.yyds-pip-audit]section inpyproject.toml.- Multiple Formats: Outputs audit results as a beautiful terminal table, standard
requirements.txtformat, orJSONformat. - Industrial Requirements Checking: Offers a
--checkflag to scan and compare against a requirements file, revealing missing and unused dependencies. Supports recursive requirements (-r), editable requirements (-e), PEP 508 direct references (requests @ https://...), egg fragments in Git/VCS URLs (#egg=name), and environment markers. - PEP 503 Normalization: Adheres to PyPI standard normalization for package names comparison.
- CI-friendly Warning System: Prints warning logs to stderr and skips files gracefully in case of syntax or permission errors instead of crashing.
- Wide Compatibility: Compatible with Python 3.7+ across all platforms.
🚀 Installation
Install it using pip locally or from PyPI:
# Install in editable/development mode
pip install -e .
# Normal installation
pip install -U yyds-pip-audit
🛠 Usage
Once installed, you can use the yyds-pip-audit or yyds_pip_audit command.
1. Basic Audit
Run it in your project's root folder:
yyds-pip-audit
Or target a specific directory:
yyds-pip-audit /path/to/project
2. Export Dependencies
Save audited dependencies in different file formats:
# Save to standard requirements.txt format
yyds-pip-audit -f requirements -o requirements.txt
# Save to JSON format
yyds-pip-audit -f json -o dependencies.json
3. Check Against Requirements File
Check if the codebase imports any package not registered in requirements, or if the requirements file has packages never imported:
yyds-pip-audit --check requirements.txt
4. Custom Exclude Folders
Use -e or --exclude to ignore additional folders. You can pass multiple options, use comma-separated paths, or specify relative paths:
# Exclude multiple folders
yyds-pip-audit -e temp_folder -e tests/mocks
# Exclude via comma-separated list
yyds-pip-audit -e temp_folder,build_assets
# Exclude specific relative path
yyds-pip-audit -e src/data
5. pyproject.toml Configuration
You can write configuration options directly in your project's pyproject.toml file under the [tool.yyds-pip-audit] section:
[tool.yyds-pip-audit]
exclude = ["build_assets", "custom_dir"]
format = "json"
output = "audit_report.json"
Command-line parameters always override values from the configuration file.
📋 Command Line Interface
Usage: yyds-pip-audit [OPTIONS] [DIRECTORY]
yyds-pip-audit: A robust Python package import dependency auditor and PyPI mapper.
Options:
-o, --output PATH Save dependencies output to target file (e.g. requirements.txt)
-f, --format [text|requirements|json]
Output format: text (colored table), requirements (standard), json (JSON data) [default: text]
-e, --exclude TEXT Extra directory names to exclude (can be specified multiple times)
-c, --check PATH Compare against an existing requirements file to detect missing or unused packages
--version Show the version and exit.
--help Show this message and exit.
💡 How the Mapping Works
Many PyPI packages use import names that differ from their PyPI name, e.g.:
import cv2->opencv-pythonimport PIL->Pillowimport yaml->PyYAMLimport fitz->PyMuPDF
yyds-pip-audit resolves this mapping in two ways:
- Local Metadata Scanning: Traverses installed libraries in the current Python environment and parses their metadata (
top_level.txt). - Hardcoded Fallbacks: Includes a default mapping mapping for common packages that might not be installed or don't declare
top_level.txt.
📄 License
This project is licensed under the MIT License.
Metadata
Release files for yyds-pip-audit 0.2.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yyds_pip_audit-0.2.11.tar.gz | 19.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yyds_pip_audit-0.2.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.7 kB
Release files / yyds_pip_audit-0.2.11.tar.gz
| Download URL | yyds_pip_audit-0.2.11.tar.gz |
|---|---|
| Size | 19.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff318e23d439d57acb5e456403dc6f80d861b0e7c6c688272561af324abfe8ba
|
|
BLAKE2b-256 checksum How to use checksums |
01c42ae7279797f7fb5f34541b2c94a9242fb53092ceaaa92ec07bcf0964572d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Release files / yyds_pip_audit-0.2.11-py3-none-any.whl
| Download URL | yyds_pip_audit-0.2.11-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c482a5b199c307fcbafa449c3e546381169fccae93b6e2a3f81088dd60321967
|
|
BLAKE2b-256 checksum How to use checksums |
3f33c3cced0284f2aed420c735ebb5b3eeb389081d95ad027fb1b901822f64a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|