Skip to main content

Security vulnerability auditing tool for Python packages

Project description

🐍 PySentry

Help to test and improve

A fast, reliable security vulnerability scanner for Python projects, written in Rust.

Overview

PySentry audits Python projects for known security vulnerabilities by analyzing dependency files (uv.lock, pyproject.toml, requirements.txt) and cross-referencing them against multiple vulnerability databases. It provides comprehensive reporting with support for various output formats and filtering options.

Key Features

  • Multiple Project Formats: Supports uv.lock, pyproject.toml, and requirements.txt files
  • External Resolver Integration: Leverages uv and pip-tools for accurate requirements.txt constraint solving
  • Multiple Data Sources:
    • PyPA Advisory Database (default)
    • PyPI JSON API
    • OSV.dev (Open Source Vulnerabilities)
  • Flexible Output: Human-readable, JSON, and SARIF formats
  • Performance Focused:
    • Written in Rust for speed
    • Async/concurrent processing
    • Intelligent caching system
  • Comprehensive Filtering:
    • Severity levels (low, medium, high, critical)
    • Dependency types (production, development, optional)
    • Direct vs. transitive dependencies
  • Enterprise Ready: SARIF output for IDE/CI integration

Installation

Choose the installation method that works best for you:

⚡ Via uvx (Recommended for occasional use)

Run directly without installing (requires uv):

uvx pysentry-rs /path/to/project

This method:

  • Runs the latest version without installation
  • Automatically manages Python environment
  • Perfect for CI/CD or occasional security audits
  • No need to manage package versions or updates

📦 From PyPI (Python Package)

For Python 3.8+ on Linux and macOS:

pip install pysentry-rs

Then use it with Python:

python -m pysentry /path/to/project
# or directly if scripts are in PATH
pysentry-rs /path/to/project

⚡ From Crates.io (Rust Package)

If you have Rust installed:

cargo install pysentry

💾 From GitHub Releases (Pre-built Binaries)

Download the latest release for your platform:

  • Linux x64: pysentry-linux-x64.tar.gz
  • Linux x64 (musl): pysentry-linux-x64-musl.tar.gz
  • Linux ARM64: pysentry-linux-arm64.tar.gz
  • macOS x64: pysentry-macos-x64.tar.gz
  • macOS ARM64: pysentry-macos-arm64.tar.gz
  • Windows x64: pysentry-windows-x64.zip
# Example for Linux x64
curl -L https://github.com/nyudenkov/pysentry/releases/latest/download/pysentry-linux-x64.tar.gz | tar -xz
./pysentry-linux-x64/pysentry --help

🔧 From Source

git clone https://github.com/nyudenkov/pysentry
cd pysentry
cargo build --release

The binary will be available at target/release/pysentry.

Requirements

  • For uvx: Python 3.8+ and uv installed (Linux/macOS only)
  • For binaries: No additional dependencies
  • For Python package: Python 3.8+ (Linux/macOS only)
  • For Rust package and source: Rust 1.79+

Platform Support

Installation Method Linux macOS Windows
uvx
PyPI (pip)
Crates.io (cargo)
GitHub Releases
From Source

Note: Windows Python wheels are not available due to compilation complexity. Windows users should use the pre-built binary from GitHub releases, install via cargo and build from source.

CLI Command Names

  • Rust binary: pysentry (when installed via cargo or binary releases)
  • Python package: pysentry-rs (when installed via pip or uvx)

Both variants support identical functionality. The resolver tools (uv, pip-tools) must be available in your current environment regardless of which PySentry variant you use.

Requirements.txt Support Prerequisites

To scan requirements.txt files, PySentry requires an external dependency resolver to convert version constraints (e.g., flask>=2.0,<3.0) into exact versions for vulnerability scanning.

Install a supported resolver:

# uv (recommended - fastest, Rust-based)
pip install uv

# pip-tools (widely compatible, Python-based)
pip install pip-tools

Environment Requirements:

  • Resolvers must be available in your current environment
  • If using virtual environments, activate your venv before running PySentry:
    source venv/bin/activate  # Linux/macOS
    venv\Scripts\activate     # Windows
    pysentry /path/to/project
    
  • Alternatively, install resolvers globally for system-wide availability

Auto-detection: PySentry automatically detects and prefers: uv > pip-tools. Without a resolver, only uv.lock and pyproject.toml files can be scanned.

Quick Start

Basic Usage

# Using uvx (recommended for occasional use)
uvx pysentry-rs
uvx pysentry-rs /path/to/python/project

# Using installed binary
pysentry
pysentry /path/to/python/project

# Scan requirements.txt (auto-detects resolver)
pysentry /path/to/project

# Force specific resolver
pysentry --resolver uv /path/to/project
pysentry --resolver pip-tools /path/to/project

# Include development dependencies
pysentry --dev

# Filter by severity (only show high and critical)
pysentry --severity high

# Output to JSON file
pysentry --format json --output audit-results.json

Advanced Usage

# Using uvx for comprehensive audit
uvx pysentry-rs --dev --optional --format sarif --output security-report.sarif

# Check only direct dependencies using OSV database
uvx pysentry-rs --direct-only --source osv

# Or with installed binary
pysentry --dev --optional --format sarif --output security-report.sarif
pysentry --direct-only --source osv

# Ignore specific vulnerabilities
pysentry --ignore CVE-2023-12345 --ignore GHSA-xxxx-yyyy-zzzz

# Disable caching for CI environments
pysentry --no-cache

# Verbose output for debugging
pysentry --verbose

Advanced Requirements.txt Usage

# Scan multiple requirements files
pysentry --requirements requirements.txt --requirements requirements-dev.txt

# Check only direct dependencies from requirements.txt
pysentry --direct-only --resolver uv

# Ensure resolver is available in your environment
source venv/bin/activate  # Activate your virtual environment first
pysentry /path/to/project

# Debug requirements.txt resolution
pysentry --verbose --resolver uv /path/to/project

Configuration

Command Line Options

Option Description Default
--format Output format: human, json, sarif human
--severity Minimum severity: low, medium, high, critical low
--source Vulnerability source: pypa, pypi, osv pypa
--dev Include development dependencies false
--optional Include optional dependencies false
--direct-only Check only direct dependencies false
--ignore Vulnerability IDs to ignore (repeatable) []
--output Output file path stdout
--no-cache Disable caching false
--cache-dir Custom cache directory ~/.cache/pysentry
--verbose Enable verbose output false
--quiet Suppress non-error output false
--resolver Dependency resolver: auto, uv, pip-tools auto
--requirements Additional requirements files (repeatable) []

Cache Management

PySentry uses an intelligent caching system to avoid redundant API calls:

  • Default Location: ~/.cache/pysentry/ (or system temp directory)
  • TTL-based Expiration: Separate expiration for each vulnerability source
  • Atomic Updates: Prevents cache corruption during concurrent access
  • Custom Location: Use --cache-dir to specify alternative location

To clear the cache:

rm -rf ~/.cache/pysentry/

Supported Project Formats

uv.lock Files (Recommended)

PySentry has support for uv.lock files:

  • Exact version resolution
  • Complete dependency graph analysis
  • Source tracking
  • Dependency classification (main, dev, optional) including transitive dependencies

requirements.txt Files (External Resolution)

Advanced support for requirements.txt files using external dependency resolvers:

Key Features:

  • Dependencies Resolution: Converts version constraints (e.g., flask>=2.0,<3.0) to exact versions using mature external tools
  • Multiple Resolver Support:
    • uv: Rust-based resolver, extremely fast and reliable (recommended)
    • pip-tools: Python-based resolver using pip-compile, widely compatible
  • Auto-detection: Automatically detects and uses the best available resolver in your environment
  • Multiple File Support: Combines requirements.txt, requirements-dev.txt, requirements-test.txt, etc.
  • Dependency Classification: Distinguishes between direct and transitive dependencies
  • Isolated Execution: Resolvers run in temporary directories to prevent project pollution
  • Complex Constraint Handling: Supports version ranges, extras, environment markers, and conflict resolution

Resolution Workflow:

  1. Detects requirements.txt files in your project
  2. Auto-detects available resolver (uv or pip-tools) in current environment
  3. Resolves version constraints to exact dependency versions
  4. Scans resolved dependencies for vulnerabilities
  5. Reports findings with direct vs. transitive classification

Environment Setup:

# Ensure resolver is available in your environment
source venv/bin/activate      # Activate virtual environment
pip install uv               # Install preferred resolver
pysentry /path/to/project    # Run security scan

pyproject.toml Files (External Resolution)

Support for projects without lock files:

  • Parses version constraints from pyproject.toml
  • Resolver Required: Like requirements.txt, needs external resolvers (uv or pip-tools) to convert version constraints to exact versions for accurate vulnerability scanning
  • Limited dependency graph information compared to lock files
  • Works with both Poetry and PEP 621 formats

Vulnerability Data Sources

PyPA Advisory Database (Default)

  • Comprehensive coverage of Python ecosystem
  • Community-maintained vulnerability database
  • Regular updates from security researchers

PyPI JSON API

  • Official PyPI vulnerability data
  • Real-time information
  • Limited to packages hosted on PyPI

OSV.dev

  • Cross-ecosystem vulnerability database
  • Google-maintained infrastructure

Output Formats

Human-Readable (Default)

Most comfortable to read.

JSON

{
  "summary": {
    "total_dependencies": 245,
    "vulnerable_packages": 2,
    "total_vulnerabilities": 3,
    "by_severity": {
      "critical": 1,
      "high": 1,
      "medium": 1,
      "low": 0
    }
  },
  "vulnerabilities": [...]
}

SARIF (Static Analysis Results Interchange Format)

Compatible with GitHub Security tab, VS Code, and other security tools.

Performance

PySentry is designed for speed and efficiency:

  • Concurrent Processing: Vulnerability data fetched in parallel
  • Smart Caching: Reduces API calls and parsing overhead
  • Efficient Matching: In-memory indexing for fast vulnerability lookups
  • Streaming: Large databases processed without excessive memory usage

Requirements.txt Resolution Performance

PySentry leverages external resolvers for optimal performance:

  • uv resolver: 2-10x faster than pip-tools, handles large dependency trees efficiently
  • pip-tools resolver: Reliable fallback, slower but widely compatible
  • Isolated execution: Prevents project pollution while maintaining security

Benchmarks

Typical performance on a project with 100+ dependencies:

  • Cold cache: 15-30 seconds
  • Warm cache: 2-5 seconds
  • Memory usage: ~50MB peak

Development

Building from Source

git clone https://github.com/nyudenkov/pysentry
cd pysentry
cargo build --release

Running Tests

cargo test

Project Structure

src/
├── main.rs           # CLI interface
├── lib.rs            # Library API
├── cache/            # Caching system
├── dependency/       # Dependency scanning
├── output/           # Report generation
├── parsers/          # Project file parsers
├── providers/        # Vulnerability data sources
├── types.rs          # Core type definitions
└── vulnerability/    # Vulnerability matching

Troubleshooting

Common Issues

Error: "No lock file or pyproject.toml found"

# Ensure you're in a Python project directory
ls pyproject.toml uv.lock requirements.txt

# Or specify the path explicitly
pysentry /path/to/python/project

Error: "No dependency resolver found" or "uv resolver not available"

# Install a supported resolver in your environment
pip install uv           # Recommended - fastest
pip install pip-tools    # Alternative

# Verify resolver is available
uv --version
pip-compile --version

# If using virtual environments, ensure resolver is installed there
source venv/bin/activate
pip install uv
pysentry /path/to/project

Error: "Failed to resolve requirements"

# Check your requirements.txt syntax
cat requirements.txt

# Try different resolver
pysentry --resolver pip-tools  # if uv fails
pysentry --resolver uv         # if pip-tools fails

# Ensure you're in correct environment
which python
which uv  # or which pip-compile

# Debug with verbose output
pysentry --verbose /path/to/project

Error: "Failed to fetch vulnerability data"

# Check network connectivity
curl -I https://osv-vulnerabilities.storage.googleapis.com/

# Try with different source
pysentry --source pypi

Slow requirements.txt resolution

# Use faster uv resolver instead of pip-tools
pysentry --resolver uv

# Install uv for better performance (2-10x faster)
pip install uv

# Or use uvx for isolated execution
uvx pysentry-rs --resolver uv /path/to/project

Requirements.txt files not being detected

# Ensure requirements.txt exists
ls requirements.txt

# Specify path explicitly
pysentry /path/to/python/project

# Include additional requirements files
pysentry --requirements requirements-dev.txt --requirements requirements-test.txt

# Check if higher-priority files exist (they take precedence)
ls uv.lock pyproject.toml

Performance Issues

# Clear cache and retry
rm -rf ~/.cache/pysentry
pysentry

# Use verbose mode to identify bottlenecks
pysentry --verbose

Acknowledgments

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

pysentry_rs-0.1.5.tar.gz (99.8 kB view details)

Uploaded Source

Built Distributions

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

pysentry_rs-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pysentry_rs-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pysentry_rs-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pysentry_rs-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pysentry_rs-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pysentry_rs-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pysentry_rs-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pysentry_rs-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pysentry_rs-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pysentry_rs-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pysentry_rs-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pysentry_rs-0.1.5-cp38-cp38-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file pysentry_rs-0.1.5.tar.gz.

File metadata

  • Download URL: pysentry_rs-0.1.5.tar.gz
  • Upload date:
  • Size: 99.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pysentry_rs-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7b4520507e826b0997b54a3d6ffe4877872eb92c5d3636ec61379cdea10092b5
MD5 625e99ebbe34919a9def0b7b3d9b2761
BLAKE2b-256 bd7cfdf0f7f08cca88d03057ce267614052a189dffdef63c459078536a5716db

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ab1ef4a91e3530623acaee4604f97c5508a7e2e0f0c50173e53bf0568789bec
MD5 b12bd763084c0546179bfa5ce224212e
BLAKE2b-256 9ecb30bdb19939a0bc0adb1efa904089da00b520dbf581e0e36638ae846d0b51

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 952c15120ae050220173616a2476b4c606f2e9044bc37747385c9269b1a6fa37
MD5 618c223e441ce12cda2c9a685703faca
BLAKE2b-256 4d25ee7916e7db60a53327353d5aead18122b61a62fe280fe970af180f5a1501

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9b0722490f10422a71ea8e7c953244231e632f7cb4499ca25ecd4d80930b601c
MD5 4bb302cee1626ffcdf27099e65df0d42
BLAKE2b-256 e833df8ef3de941d7587f792dfeddb2f448b90c58fd32e16fcacec56adceecb6

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 736e7307397e52b60090cc65dbe1eac54d891ad33cc9eca9ff0a1522ede8fa25
MD5 24e38064369ec01d1bd09f6d483e498b
BLAKE2b-256 c5cacc7d50ba9daebf92be2317b8cd0d2aac1a69d9cd4b3e54f4b66e90784d37

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9d65dde37e75b77ba84c5d50455b722683155e0842b473ad7fefecde5f36627f
MD5 1d4448fca74c4770da074c717b9ea802
BLAKE2b-256 a03ca35ae78cc76b29122f2b700480580f78a296087c51e45a089b32529f07c4

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eea2001c82895d679088cae2ea9ca73f8cba0ad1a6fbef994831506445c60ae7
MD5 04ab3175cc6a03c1f7bb36297bb03d2a
BLAKE2b-256 a6ad4ffe655d5efad43eb82ed52362c5ed8b8dee3336a643fa08fd9eb9259d35

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad4e2e11f7eae5c8fbaef48a550718a9ca64c56f316f1be413d8be0921b32e2b
MD5 515f2dcc90bcb595eb53b3a607bebf98
BLAKE2b-256 b58eead5747a5efd9b291775fcc5ca5b4e109fd31caf217710b954fb46420136

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bdd6151da876e3600ca12ce2479923728c2e82742742f47030ba67fca3ae99f4
MD5 b086ac40303f0a660ef25536eaa77910
BLAKE2b-256 cce8270a505a3e7cd9077465ffabb74935a0df78bba567c10da55269e0a1282d

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7874b5ee415b7ca036890d3210cba09a925d682852bb210f2e67584b1121ff7
MD5 44b8d742a6916a77f20eb1507da01b9d
BLAKE2b-256 85cf283f87f9a7fe07c531cf24bc9677d6325a0316fa74226116f0ccb9c22f23

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e1ad478d88d0a46ef803e50029cef64b9ffcc5c2e43354634993b9dcb47021bc
MD5 8e17959dad7ad429cdb2d08211a166b2
BLAKE2b-256 2caceab47015b7123e0ea601d75877b8f16f3988e89710eacdff3f1b1f5a8eee

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf03b39e0d4082a3a46e9b5e42fdbdd0a96a2e39319b63da911b68c407b73824
MD5 dea5ab4238e92e082b23bcb0efd08ca7
BLAKE2b-256 e3bd19b285cfde40287242ea1f76b944a8ac1dfaeaa077af50ea497a997a4290

See more details on using hashes here.

File details

Details for the file pysentry_rs-0.1.5-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pysentry_rs-0.1.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7d4b762a2843acb1c2e69ed1293d144bc4e9166fac45b3d6113fbb0ad967ac3
MD5 72bc864b39dd8f050ac7ff023766d894
BLAKE2b-256 bf4c285f6b0ad6935f428edf884ac8ba05d98a12f9e778a45c6c8fd7912ee319

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