Stops malicious PyPI packages before installation
Project description
pip-guardian
pip-guardian is a security gate in front of pip install to reduce PyPI supply-chain risk.
Why this exists
Package ecosystems are a common attack path. pip-guardian checks package metadata and distribution contents before install, then decides ALLOW, WARN, or BLOCK.
Feature set
1) Pre-install risk policy
- Version age rules:
- block if version is very new (default
< 5h) - warn if version is recent (default
< 48h)
- block if version is very new (default
- Blocks yanked releases.
- Blocks known-compromised versions from local blocklist.
- Blocks maintainer identities from local blocklist.
2) Deep artifact scanning
- Downloads wheel/sdist artifacts from PyPI before install.
- Verifies artifact SHA256 against PyPI metadata.
- Static scan heuristics for:
- executable
.pthstartup hooks sitecustomize.py/usercustomize.py- obfuscated payload patterns (e.g., long base64 + dynamic execution)
- credential-exfiltration-like behavior
- persistence indicators (e.g., systemd artifacts)
- Kubernetes lateral-movement indicators
- executable
3) Built-in incident guard (LiteLLM March 2026)
- Blocks:
litellm==1.82.7litellm==1.82.8
- Runbook:
docs/INCIDENT_LITELLM_2026.md
4) CI-friendly JSON mode
--jsonemits one machine-readable JSON object.--yesallows non-interactive proceed onWARN.- Exit codes:
0install succeeded1blocked, warn-not-confirmed, or pip install failure2usage/argument errors
5) Logging
- Decision logs written as JSONL.
- Primary path:
~/.pip_guardian/guardian.log - Fallback path (if home not writable):
./.pip_guardian/guardian.log
Installation
Install from PyPI:
python -m pip install pip-guardian
Upgrade:
python -m pip install --upgrade pip-guardian
CLI entrypoint fix
Earlier releases had CLI entrypoint issues for some users. This is now fixed.
Upgrade and try again:
python -m pip install --upgrade pip-guardian
pip-guardian install requests
Alternative commands that now work:
pip_guardian install requests
guardian install requests
python -m guardian install requests
Install from source (development):
git clone https://github.com/AnantDhavale/pip-guardian.git
cd pip-guardian
python -m pip install .
Usage
guardian install requests
guardian install litellm==1.82.8
guardian install fastapi --index-url https://pypi.org/simple
guardian install requests --json --yes
Policy and IOC files
policies/config.yaml:- age thresholds
- deep-scan score thresholds
- executable
.pthblocking toggle
policies/blocklist.json:- package/version deny list
- maintainer deny list
Repository structure
guardian/cli.py- command entrypointguardian/policy_engine.py- risk decision logicguardian/scanner.py- deep artifact scanningguardian/pypi_checker.py- PyPI metadata collectionguardian/logger.py- local decision logging
Notes
- This reduces risk but is not a full malware sandbox.
- For production, use pinned dependencies and hash-locked installs.
Author
Anant Dhavale
anantdhavale@gmail.com
Reach out
If you are using it and finding it useful, please drop me a note. I would appreciate that ! anantdhavale@gmail.com
Check out homer-core. It's the governance middle-ware your enteprise needs, reach out for a free POC. wwww.homersemantics.com info@homersemantics.com
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 pip_guardian-1.0.1.tar.gz.
File metadata
- Download URL: pip_guardian-1.0.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
369656434928fe459e61f5a32d1dda245e2d678bddc11f054f130fcfae7bfa4e
|
|
| MD5 |
39410ba8310271c4af7373278068b8a5
|
|
| BLAKE2b-256 |
47b14fc3112fff4bd7f8b218c76800808dd239377646a2998d51cbe3aa9c837d
|
Provenance
The following attestation bundles were made for pip_guardian-1.0.1.tar.gz:
Publisher:
python-publish.yml on AnantDhavale/pip-guardian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pip_guardian-1.0.1.tar.gz -
Subject digest:
369656434928fe459e61f5a32d1dda245e2d678bddc11f054f130fcfae7bfa4e - Sigstore transparency entry: 1504097218
- Sigstore integration time:
-
Permalink:
AnantDhavale/pip-guardian@c63aca3ff65aaa3d2d4d9cc4cf63d03690358de1 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/AnantDhavale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c63aca3ff65aaa3d2d4d9cc4cf63d03690358de1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pip_guardian-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pip_guardian-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87697b385b9a2105b534fb6fa2591ce5c9d58f6051ec4a8304b9e8258defe36d
|
|
| MD5 |
5c43e44d7726e89fe4b1703d5f15d4c9
|
|
| BLAKE2b-256 |
89646795c4161c3e7ac6fb258bd377ee8bae233a0c809c53289474dae54e228f
|
Provenance
The following attestation bundles were made for pip_guardian-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on AnantDhavale/pip-guardian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pip_guardian-1.0.1-py3-none-any.whl -
Subject digest:
87697b385b9a2105b534fb6fa2591ce5c9d58f6051ec4a8304b9e8258defe36d - Sigstore transparency entry: 1504097369
- Sigstore integration time:
-
Permalink:
AnantDhavale/pip-guardian@c63aca3ff65aaa3d2d4d9cc4cf63d03690358de1 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/AnantDhavale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c63aca3ff65aaa3d2d4d9cc4cf63d03690358de1 -
Trigger Event:
release
-
Statement type: