Skip to main content

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)
  • 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 .pth startup 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

3) Built-in incident guard (LiteLLM March 2026)

  • Blocks:
    • litellm==1.82.7
    • litellm==1.82.8
  • Runbook:
    • docs/INCIDENT_LITELLM_2026.md

4) CI-friendly JSON mode

  • --json emits one machine-readable JSON object.
  • --yes allows non-interactive proceed on WARN.
  • Exit codes:
    • 0 install succeeded
    • 1 blocked, warn-not-confirmed, or pip install failure
    • 2 usage/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 .pth blocking toggle
  • policies/blocklist.json:
    • package/version deny list
    • maintainer deny list

Repository structure

  • guardian/cli.py - command entrypoint
  • guardian/policy_engine.py - risk decision logic
  • guardian/scanner.py - deep artifact scanning
  • guardian/pypi_checker.py - PyPI metadata collection
  • guardian/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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pip_guardian-1.0.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

pip_guardian-1.0.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

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

Hashes for pip_guardian-1.0.1.tar.gz
Algorithm Hash digest
SHA256 369656434928fe459e61f5a32d1dda245e2d678bddc11f054f130fcfae7bfa4e
MD5 39410ba8310271c4af7373278068b8a5
BLAKE2b-256 47b14fc3112fff4bd7f8b218c76800808dd239377646a2998d51cbe3aa9c837d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pip_guardian-1.0.1.tar.gz:

Publisher: python-publish.yml on AnantDhavale/pip-guardian

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pip_guardian-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87697b385b9a2105b534fb6fa2591ce5c9d58f6051ec4a8304b9e8258defe36d
MD5 5c43e44d7726e89fe4b1703d5f15d4c9
BLAKE2b-256 89646795c4161c3e7ac6fb258bd377ee8bae233a0c809c53289474dae54e228f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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