Skip to main content

๐Ÿ PYGARDE โ€” Python Supply Chain Security Guardian. Scans, audits and hardens Python package manager security.

Project description

๐Ÿ PYGARDE (pyw)

Python Supply Chain Security Guardian

PYGARDE is a CLI security tool that scans, audits and hardens your Python package ecosystem against supply-chain attacks โ€” before malicious code ever runs on your machine.

  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—    โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
  โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ•šโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘    โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—
  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• โ–ˆโ–ˆโ•‘ โ–ˆโ•— โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘
  โ–ˆโ–ˆโ•”โ•โ•โ•โ•   โ•šโ–ˆโ–ˆโ•”โ•  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘
  โ–ˆโ–ˆโ•‘        โ–ˆโ–ˆโ•‘   โ•šโ–ˆโ–ˆโ–ˆโ•”โ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•
  โ•šโ•โ•        โ•šโ•โ•    โ•šโ•โ•โ•โ•šโ•โ•โ• โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•

Python PyPI License: MIT


Features

Feature Description
Deep scan Download and scan any PyPI package without installing it
Pre-install gate Intercept and scan packages before they touch your environment
Dependency audit Audit all project dependencies against known CVEs and custom rules
RC hardening Detect and fix misconfigurations in pip.conf, poetry.toml and uv.toml
Version diff Compare two package versions and scan the code delta for injected threats
Health check doctor command scores your project's overall security posture

Detection Rules

Rule Detects
install-scripts Malicious setup.py hooks, .pth injection
network-access Suspicious imports and outbound URLs (pastebin, ngrok, hardcoded IPs)
code-execution eval, exec, os.system, subprocess with shell=True, pickle.loads
obfuscation base64.b64decode payloads, marshal.loads, high-entropy strings
data-exfiltration os.environ combined with outbound HTTP, sensitive key access
hidden-chars Zero-width spaces, Trojan Source (CVE-2021-42574), Cyrillic homoglyphs
typosquatting Levenshtein-distance โ‰ค 2 against 80+ popular PyPI packages

Installation

# From PyPI (once published)
pip install pygarde

# Or install from source
git clone https://github.com/destbreso/pygarde
cd pygarde
pip install -e ".[dev]"

Requirements: Python 3.10+


Quick Start

# Initialize security configuration
pyw init

# Scan a package before installing
pyw scan requests

# Install with security gate
pyw install requests flask

# Audit all project dependencies
pyw audit

# Health check
pyw doctor

# Harden PM configuration
pyw harden

# Compare two versions
pyw diff numpy

Commands

pyw scan <package> [--version]

Deep-scan a PyPI package for security threats without installing it.

pyw scan requests
pyw scan requests --version 2.28.0
pyw scan suspicious-pkg --severity high
pyw scan malware --ci --json

Options:

Flag Description
--version, -v Version to scan (interactive picker if omitted)
--severity, -s Minimum severity to display (low | medium | high | critical)
--page-size Findings per page (default: 20)
--ci Non-interactive, exits with code 1 if threats found
--json Machine-readable JSON output

pyw install [packages...]

Install packages with a pre-install security scan.

pyw install requests flask sqlalchemy
pyw install pytest --dev
pyw install requests --force        # install despite findings
pyw install requests --skip-scan    # bypass scanning

pyw audit [--deep]

Audit all project dependencies.

  • Runs native PM audit (pip-audit, pipenv check, etc.)
  • With --deep: downloads and static-scans each dependency
pyw audit
pyw audit --deep
pyw audit --ci --json

pyw doctor

Security health check. Scores your project 0โ€“100% across:

  • .pygarde.yml present
  • Lockfile present
  • PM config security (via RC analyzer)
  • No dangerous PM settings
  • All detection rules enabled
  • Allowlist not overly permissive

pyw diff <package> [--target]

Compare two versions of a package and scan the diff for injected code.

pyw diff requests
pyw diff numpy --target 1.26.0
pyw diff attrs --show-diff       # show line-level diffs

pygarde highlights:

  • Added / removed / modified files
  • New attack patterns in the diff (eval, subprocess, network calls)

pyw harden [--yes] [--dry-run]

Audit and fix PM security configuration files.

pyw harden
pyw harden --yes              # auto-apply at configured level
pyw harden --dry-run          # show issues only

Harden levels:

Level Scope
minimal Critical + high โ€” the non-negotiables
recommended Critical + high + medium โ€” solid baseline (default)
strict All findings including low-impact settings

pip.conf settings managed:

Setting Level Why
require-hashes = true critical Prevents MITM/tampered packages
no-binary (avoid for critical pkgs) medium Prefer auditable source
index-url medium Ensure official PyPI registry
trusted-host (danger) critical Disables SSL verification

pyw init

Interactive wizard to generate .pygarde.yml and apply RC hardening.


pyw config [show|edit|reset|path]

Manage configuration.

pyw config show         # display current config
pyw config path         # print config file path
pyw config edit         # open in $EDITOR
pyw config reset        # reset to defaults

Configuration

pygarde reads .pygarde.yml in the project root.

severity:
  threshold: medium       # ignore findings below this level
  fail_ci: high           # exit 1 in CI when findings reach this level

rules:
  install_scripts: true
  network_access: true
  code_execution: true
  obfuscation: true
  data_exfiltration: true
  hidden_chars: true
  typosquatting: true

policies:
  enforce_rc_security: true
  enforce_lockfile: true
  enforce_exact_versions: false
  audit_on_install: true
  registry_url: "https://pypi.org/simple/"
  harden_level: recommended   # minimal | recommended | strict

allowlist:
  - urllib3      # known false-positive
  - certifi

blocklist:
  - malicious-pkg
  - evil-package

Supported Package Managers

PM Detection Install Audit Harden
pip โœ” โœ” โœ” (pip-audit) โœ” (pip.conf)
poetry โœ” โœ” โœ” โœ” (poetry.toml)
uv โœ” โœ” โ€” โœ” (uv.toml)
pipenv โœ” โœ” โœ” (pipenv check) โ€”
pdm โœ” โœ” โ€” โ€”
conda โœ” โ€” โ€” โ€”

Running Tests

pip install -e ".[dev]"
pytest
pytest -v tests/test_rules.py
pytest --tb=short

License

MIT โ€” see LICENSE

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

pygarde-1.0.0.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

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

pygarde-1.0.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file pygarde-1.0.0.tar.gz.

File metadata

  • Download URL: pygarde-1.0.0.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pygarde-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4757b997f520ea21bbbd7c4154d4e7af1505408d7d6f1ff18208914e379b9feb
MD5 d007b51ae2a4517124a887378452e6d8
BLAKE2b-256 b06321420656cb13a298a378a142c341fc2bd7527ec706dd65b050e6ff5e7feb

See more details on using hashes here.

File details

Details for the file pygarde-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pygarde-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pygarde-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89d1c06cc162fd158c4742c5f88fcb7b4bc0e19e6398ebb4850a582f4ae501b0
MD5 96e3fa0b84f3381677bef77f71cd75b3
BLAKE2b-256 01f6bffd8714548a39ad13adc7fa9e7ad273eb696cef35d99e6d16ffcc3129a5

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