Pipwatch
Detect import statements in Python files and install the corresponding PyPI packages.
Pipwatch parses your Python files for imports, filters out standard library modules, maps import names to PyPI package names where they differ (e.g. PIL to pillow, cv2 to opencv-python), and installs whatever is missing.
Features
Import Detection
- Parses import statements using the AST module and filters out standard library modules
- Also detects
# pip installcomments and version specifiers in your code - Maps import names to correct PyPI package names (e.g.
sklearn->scikit-learn) - Skips packages that are already installed
Mapping Registry
- Package mappings hosted on GitHub and fetched at runtime
- Local cache with 24-hour TTL so it doesn't hit the network on every run
- Falls back to bundled
mappings.jsonwhen offline - New mappings can be added via pull request
CLI Flags
--dry-run- Preview what would be installed without installing anything--generate- Generate arequirements.txtfile from detected dependencies--verbose- Enable detailed debug logging--yes- Auto-confirm installations (useful for CI)--output- Specify custom output path for generated requirements files--update-mappings- Fetch latest mappings from GitHub--clear-cache- Clear cached mappings--show-mappings- Show mapping statistics
Directory Scanning
- Point pipwatch at a directory instead of a single file to scan everything
- Automatically skips
.venv,node_modules,__pycache__,build,dist, and other junk directories
Installer Support
- Works with both pip and uv — if uv is on your PATH, pipwatch will use it automatically
Installation
pip install pipwatch
or with uv:
uv add pipwatch
For development:
pip install pipwatch[dev]
Usage
Basic Usage
Analyze a single file:
pipwatch script.py
Analyze all Python files in the current directory & subdirectories:
pipwatch .
Analyze all Python files in a specific folder:
pipwatch myfolder/
Dry Run (Preview Only)
See what would be installed without installing:
pipwatch script.py --dry-run
Or for an entire directory:
pipwatch . --dry-run
Example output:
INFO: Analyzing script.py...
INFO: Found the following dependencies from import statements:
INFO: • bs4 → beautifulsoup4
INFO: • numpy
INFO: • pandas
[DRY RUN] Would install the following packages:
• beautifulsoup4
• numpy
• pandas
Generate Requirements File
Create a requirements.txt from your code:
pipwatch script.py --generate
Or with a custom output path:
pipwatch script.py --generate --output my-requirements.txt
Auto-Install (No Prompts)
For automation and CI:
pipwatch script.py --yes
Verbose Mode
Get detailed debug information:
pipwatch script.py --verbose
Manage Mappings
Update mappings from GitHub:
pipwatch --update-mappings
Show mapping statistics:
pipwatch --show-mappings
Clear cached mappings:
pipwatch --clear-cache
Package Name Mappings
Pipwatch includes 50+ mappings for cases where the import name differs from the PyPI package name:
| Import Name | Package Name |
|---|---|
PIL |
pillow |
cv2 |
opencv-python |
sklearn |
scikit-learn |
bs4 |
beautifulsoup4 |
yaml |
pyyaml |
Crypto |
pycryptodome |
jwt |
PyJWT |
| And more... |
How It Works
- Parse - Parses your Python file using the AST module
- Filter - Removes standard library imports
- Analyze - Scans for
# pip installcomments and version specifiers - Map - Maps import names to PyPI package names
- Check - Checks which packages are already installed
- Install/Generate - Installs missing packages or generates
requirements.txt
Mapping Resolution
The mapping system loads from three sources, trying each in order:
┌─────────────────┐
│ mappings.json │ (GitHub)
│ (Remote) │
└────────┬────────┘
│ Fetch (once per day)
▼
┌─────────────────┐
│ Local Cache │ (~/.pipwatch/)
│ (24hr TTL) │
└────────┬────────┘
│ Fallback
▼
┌─────────────────┐
│ Bundled File │ (Offline support)
│ (Built-in) │
└─────────────────┘
Contributing Mappings
Found a missing mapping? See docs/CONTRIBUTING_MAPPINGS.md for how to add one.
Development
Setup
git clone https://github.com/Felixdiamond/pipwatch.git
cd pipwatch
pip install -e ".[dev]"
Run Tests
pytest tests/
With coverage:
pytest tests/ --cov=src/pipwatch --cov-report=term-missing
Code Formatting
black src/ tests/
isort src/ tests/
ruff check src/ tests/ --fix
Update Mappings
Use the helper script to add or discover import-to-package mappings in
src/pipwatch/mappings.json.
Add a single mapping (validated against PyPI):
python scripts/populate_mappings.py add PIL pillow --category image-processing
Preview without writing:
python scripts/populate_mappings.py add PIL pillow --category image-processing --dry-run
Discover mappings from your installed packages and preview:
python scripts/populate_mappings.py discover
Apply discovered mappings:
python scripts/populate_mappings.py discover --apply
Preview discovered mappings without writing:
python scripts/populate_mappings.py discover --apply --dry-run
Contributing
See CONTRIBUTING.md for guidelines.
License
Created by Felix Dawodu
Metadata
Release files for pipwatch 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pipwatch-0.0.3.tar.gz | 24.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pipwatch-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.3 kB
Release files / pipwatch-0.0.3.tar.gz
| Download URL | pipwatch-0.0.3.tar.gz |
|---|---|
| Size | 24.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8ad1be9efb00d12010c5c71f812607131c23836cce053a999ffaf307c3a63b5
|
|
BLAKE2b-256 checksum How to use checksums |
deef4f67f931917db4c84c2c7a0e67a2eb6f1b723d5b9722414f90f861e899d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency logRelease files / pipwatch-0.0.3-py3-none-any.whl
| Download URL | pipwatch-0.0.3-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
543b469bfa0ff5b65da33d42cf9d6f9fbbb68f145a1dcb70747ecd8bac23d91a
|
|
BLAKE2b-256 checksum How to use checksums |
03d4ec4ad059d280bef6bce230c632eac8e7764545c51038832497aab66315a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency logSecurity for pipwatch 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pipwatch-0.0.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.