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, poetry.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, poetry.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 scopes (main only vs all [optional, dev, prod, etc] dependencies)
    • 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 poetry.lock 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

# Automatically detects project type (uv.lock, poetry.lock, pyproject.toml, requirements.txt)
pysentry /path/to/project

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

# Include all dependencies (main + dev + optional)
pysentry --all

# 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 --all --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 --all --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
--all Include all dependencies (main + dev + optional) 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

poetry.lock Files

Full support for Poetry lock files:

  • Exact Version Resolution: Scans exact dependency versions locked by Poetry
  • Lock-File Only Analysis: Relies purely on the lock file structure, no pyproject.toml parsing needed
  • Complete Dependency Tree: Analyzes all resolved dependencies including transitive ones
  • Dependency Classification: Distinguishes between main dependencies and optional groups (dev, test, etc.)
  • Source Tracking: Supports PyPI registry, Git repositories, local paths, and direct URLs

Key Features:

  • No external tools required
  • Fast parsing with exact version information
  • Handles Poetry's dependency groups and optional dependencies
  • Perfect for Poetry-managed projects with established lock files

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 poetry.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 poetry.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.2.0.tar.gz (102.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.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pysentry_rs-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pysentry_rs-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pysentry_rs-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pysentry_rs-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pysentry_rs-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pysentry_rs-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pysentry_rs-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pysentry_rs-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pysentry_rs-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pysentry_rs-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pysentry_rs-0.2.0-cp38-cp38-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pysentry_rs-0.2.0.tar.gz
  • Upload date:
  • Size: 102.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.2.0.tar.gz
Algorithm Hash digest
SHA256 3d859298e4851c8a08d81f110596707fb01b1ce8d4489769696356ccbaa6b79a
MD5 e693eb34efdca98c6ca8a1e375df817f
BLAKE2b-256 d07f8270c67b8e5d1553948070dbad7ec06c53c85784538dd2366ccbbe64cfa7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8fa99580c8e1875d367dd2f23088c7a48b5a7733442eae97778512c4685c84a1
MD5 6ea19467699e4cd0e2b32bda15f49118
BLAKE2b-256 424f6584ec7ea28667368054fb1ca0aa991216cb574ae90426971e2da3764d6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 320397e2cdd35e6075c57afe9ecd6aa50bac8894b2a2d8adb6cafda279524478
MD5 deaaf23e0539c69742afaaef8c86a633
BLAKE2b-256 96997745c1f076d6dfdf1e2673ff394a6c1e0cb9915c7bf8151f75a1cc6ce7fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2566e5098528c259d99b2bd9a537e88bebc36db93143c095f4684d51d7638d47
MD5 1c0222db10247cfe1d01b9b065a941cc
BLAKE2b-256 2f9fb8c6eec4146f9d539f98d3b1ae00dc761d2290179fdd09fba74cc78b9f1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a701b613f00ccd2a0b3e26736544ef65b96e919d264b87347b3a379103a0c99
MD5 c30654920f5a33665f218d9d12522b36
BLAKE2b-256 4a1e1c7925fbb046992098a04483697290563742a05adf1cc295d418f16e1aea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b3e6cb23b71f91a261438d8f3e80fcbb00e77c01f27ac5559bda6f35681e1058
MD5 d59781724d8de8766d49fd72fb55e121
BLAKE2b-256 c30a200ccd01891c8889c2629fca2e17985af615d615115fa3f0acbb92e29241

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ff574a5a8b71a9960b873fa0a9b1aa48f2f6e9abc32d5f62605885c6d0ce08a
MD5 57f261cf3d8e56d499000bdc9da78fd4
BLAKE2b-256 14a3bfd789acfbdaae7e5f4ebf1bbbc955533d3ded96960b2ada1b3d20a2b374

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 612478d4b3fb37de4a64409680c693184c097ebcbe763d87415b0df9dbe5d6fc
MD5 387c80a1a53f83808d5f43c857d94361
BLAKE2b-256 f8a609a5ebd91c168b92ea280cc2e369115b3f9645962db7fe86f77975434a70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b19b2183033211bd6c166d5fcb99586fa542166a9372eef83402ba515a842b9e
MD5 e10df1c2ac4470b415cc9c915b7e34ad
BLAKE2b-256 e1834002bfde68c70775ee8c9acdbdbda5d82a3bc9f216dd9ce25924cd887c62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 838f93eed53a4a9745df581bacd2e30a341738888fe4a56c6279dedf31bf67c1
MD5 02afd4718d7c738610129b34670db112
BLAKE2b-256 07e297747e264ff906ec360db30f9f83bd489bb14a26336685af765fb4428cb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9fddbd5be111362d207c2ce12a628183f517557988c17213a7a303b0efcb698
MD5 17a2b14d6fc2ed72f51e94fa6dea1f95
BLAKE2b-256 fca2eaa28ec2d66baaf32420307f39acd5d17383fd52ad79aba2494c4c1bbd39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bfc996ccdbd9bf7ed431001c65211f5c8c5ecdee1a42bcf86a6073ee244d4a22
MD5 7e9ab6795de69ca267597e6a063a3b8d
BLAKE2b-256 675f5ef78344fe152694ccee422630fe222899bd546603a907c1aec53dac9016

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysentry_rs-0.2.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d907055b3025785996372f778d521a4cc5f071c923e7d1c5d27720c324f8db3
MD5 8cc3655f623f4f9efb344579ba906509
BLAKE2b-256 fab781d806ef6e19c663a54c31db72c39559f31682b3894d44c4c4fae67bd3e1

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