🐍 PySentry
Help to test and improve | Latest PySentry - pip-audit benchmark
Please, send feedback to nikita@pysentry.com
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, Pipfile.lock, pylock.toml, pyproject.toml, Pipfile, 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,Pipfile.lock,pylock.toml,pyproject.toml,Pipfile, andrequirements.txtfiles - External Resolver Integration: Leverages
uvandpip-toolsfor accurate requirements.txt constraint solving - Multiple Data Sources (all sources used by default):
- PyPA Advisory Database
- PyPI JSON API
- OSV.dev (Open Source Vulnerabilities)
- Flexible Output for different workflows: Human-readable, JSON, SARIF, and Markdown formats
- Performance Focused:
- Written in Rust for speed
- Async/concurrent processing
- Multi-tier intelligent caching (vulnerability data + resolved dependencies)
- 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):
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.9-3.14 on Linux, macOS, and Windows:
Then use it with Python:
# or directly if scripts are in PATH
⚡ From Crates.io (Rust Package)
If you have Rust installed:
💾 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
|
🔧 From Source
The binary will be available at target/release/pysentry.
Requirements
- For uvx: Python 3.9-3.14 and uv installed
- For binaries: No additional dependencies
- For Python package: Python 3.9-3.14
- For Rust package and source: Rust 1.79+
Platform Support
| Installation Method | Linux (x64) | Linux (ARM64) | macOS (x64) | macOS (ARM64) | Windows (x64) |
|---|---|---|---|---|---|
| uvx | ✅ | ✅ | ✅ | ✅ | ✅ |
| PyPI (pip) | ✅ | ✅ | ✅ | ✅ | ✅ |
| Crates.io (cargo) | ✅ | ✅ | ✅ | ✅ | ✅ |
| GitHub Releases | ✅ | ✅ | ✅ | ✅ | ✅ |
| From Source | ✅ | ✅ | ✅ | ✅ | ✅ |
Supported Python Versions: 3.9, 3.10, 3.11, 3.12, 3.13, 3.14 Supported Architectures: x86_64 (x64), ARM64 (aarch64)
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-tools (widely compatible, Python-based)
Environment Requirements:
- Resolvers must be available in your current environment
- If using virtual environments, activate your venv before running PySentry:
- 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)
# Using installed binary
# Automatically detects project type (uv.lock, poetry.lock, Pipfile.lock, pyproject.toml, Pipfile, requirements.txt)
# Force specific resolver
# Exclude extra dependencies (only check main dependencies)
# Filter by severity (only show high and critical)
# Output to JSON file
Advanced Usage
# Using uvx for comprehensive audit (extras included by default)
# Use specific vulnerability sources (all sources used by default)
# Generate markdown report
# Control CI exit codes - only fail on critical vulnerabilities
# Or with installed binary (extras included by default)
# Ignore specific vulnerabilities
# Ignore unfixable vulnerabilities (only while they have no fix available)
# Disable caching for CI environments
# Verbose output for debugging
Advanced Requirements.txt Usage
# Scan multiple requirements files
# Check only direct dependencies from requirements.txt
# Ensure resolver is available in your environment
# Debug requirements.txt resolution
# Use longer resolution cache TTL (48 hours)
# Clear resolution cache before scanning
CI/CD Integration Examples
# Development environment - only fail on critical vulnerabilities
# Staging environment - fail on high+ vulnerabilities
# Production deployment - strict security (fail on medium+, default)
# Generate markdown report for GitHub issues/PRs
# Comprehensive audit with all sources and full reporting (extras included by default)
# CI environment with fresh resolution cache
# CI with resolution cache disabled
Pre-commit Integration
PySentry integrates seamlessly with pre-commit to automatically scan for vulnerabilities before commits.
Setup
Add PySentry to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/pysentry/pysentry-pre-commit
rev: v0.3.14
hooks:
- id: pysentry # default pysentry settings
Advanced Configuration
repos:
- repo: https://github.com/pysentry/pysentry-pre-commit
rev: v0.3.14
hooks:
- id: pysentry
args:
Installation Requirements
Pre-commit will automatically install PySentry, uv and pip-tools via PyPI.
Configuration
PySentry supports TOML-based configuration files for persistent settings management. Configuration files follow a hierarchical discovery pattern:
- Project-level (in current or parent directories, walking up to
.gitroot):.pysentry.toml(highest priority)pyproject.toml[tool.pysentry]section (lower priority, convenient for existing Python projects)
- User-level:
~/.config/pysentry/config.toml(Linux/macOS) - System-level:
/etc/pysentry/config.toml(Unix systems)
Priority: When both .pysentry.toml and pyproject.toml exist in the same directory, .pysentry.toml takes precedence. This allows you to override pyproject.toml settings when needed.
Configuration File Example (.pysentry.toml)
= 1
[]
= "json"
= "medium"
= "high"
= "all"
= false
[]
= ["pypa", "osv"]
[]
= "uv"
= "pip-tools"
[]
= true
= 48
= 72
[]
= false
= false
= "auto"
[]
= ["CVE-2023-12345", "GHSA-xxxx-yyyy-zzzz"]
= ["CVE-2025-8869"]
[]
= 120
= 30
= 3
= 1
= 60
= true
pyproject.toml Configuration
You can configure PySentry directly in your pyproject.toml using the [tool.pysentry] section:
[]
= "my-project"
= "1.0.0"
[]
= 1
[]
= "json"
= "medium"
= "high"
= "main"
= false
[]
= ["pypa", "osv"]
[]
= "uv"
= "pip-tools"
[]
= true
= 48
= 72
[]
= false
= false
= "auto"
[]
= ["CVE-2023-12345"]
= ["CVE-2025-8869"]
[]
= 120
= 30
= 3
Benefits of pyproject.toml configuration:
- Keep all project configuration in a single file
- No additional config files to manage
- Works seamlessly with existing Python project tooling
- Graceful fallback: Invalid
[tool.pysentry]sections log a warning and continue to next configuration source
Environment Variables
| Variable | Description | Example |
|---|---|---|
PYSENTRY_CONFIG |
Override config file path (supports .pysentry.toml or pyproject.toml) |
PYSENTRY_CONFIG=/path/to/pyproject.toml |
PYSENTRY_NO_CONFIG |
Disable all config file loading | PYSENTRY_NO_CONFIG=1 |
Command Line Options
| Option | Description | Default |
|---|---|---|
--format |
Output format: human, json, sarif, markdown |
human |
--severity |
Minimum severity: low, medium, high, critical |
low |
--fail-on |
Fail (exit non-zero) on vulnerabilities ≥ severity | medium |
--sources |
Vulnerability sources: pypa, pypi, osv (multiple) |
pypa,pypi,osv |
--exclude-extra |
Exclude extra dependencies (dev, optional, etc) | false |
--direct-only |
Check only direct dependencies | false |
--detailed |
Show full vulnerability descriptions instead of truncated | false |
--ignore |
Vulnerability IDs to ignore (repeatable) | [] |
--ignore-while-no-fix |
Ignore vulnerabilities only while no fix is available | [] |
--output |
Output file path | stdout |
--no-cache |
Disable all caching | false |
--cache-dir |
Custom cache directory | Platform-specific |
--resolution-cache-ttl |
Resolution cache TTL in hours | 24 |
--no-resolution-cache |
Disable resolution caching only | false |
--clear-resolution-cache |
Clear resolution cache on startup | false |
--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 multi-tier caching system for optimal performance:
Vulnerability Data Cache
- Location:
{CACHE_DIR}/pysentry/vulnerability-db/ - Purpose: Caches vulnerability databases from PyPA, PyPI, OSV
- TTL: 24 hours (configurable per source)
- Benefits: Avoids redundant API calls and downloads
Resolution Cache
- Location:
{CACHE_DIR}/pysentry/dependency-resolution/ - Purpose: Caches resolved dependencies from
uv/pip-tools - TTL: 24 hours (configurable via
--resolution-cache-ttl) - Benefits: Dramatically speeds up repeated scans of requirements.txt files
- Cache Key: Based on requirements content, resolver version, Python version, platform
Platform-Specific Cache Locations
- Linux:
~/.cache/pysentry/ - macOS:
~/Library/Caches/pysentry/ - Windows:
%LOCALAPPDATA%\pysentry\
Finding Your Cache Location: Run with --verbose to see the actual cache directory path being used.
Cache Features
- Atomic Updates: Prevents cache corruption during concurrent access
- Custom Location: Use
--cache-dirto specify alternative location - Selective Clearing: Control caching behavior per cache type
- Content-based Invalidation: Automatic cache invalidation on content changes
Cache Control Examples
# Disable all caching
# Disable only resolution caching (keep vulnerability cache)
# Set resolution cache TTL to 48 hours
# Clear resolution cache on startup (useful for CI)
# Custom cache directory
To manually clear all caches:
# Linux
# macOS
# Windows (PowerShell)
To clear only resolution cache:
# Linux
# macOS
# Windows (PowerShell)
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
Pipfile.lock Files
Full support for Pipenv lock files with exact version resolution:
- Exact Version Resolution: Scans exact dependency versions locked by Pipenv
- Lock-File Only Analysis: Relies purely on the lock file structure, no Pipfile parsing needed
- Complete Dependency Tree: Analyzes all resolved dependencies including transitive ones
- Dependency Classification: Distinguishes between default dependencies and development groups
Key Features:
- No external tools required
- Fast parsing with exact version information
- Handles Pipenv's dependency groups (default and develop)
- Perfect for Pipenv-managed projects with established lock files
Pipfile Files (External Resolution)
Support for Pipfile specification files using external dependency resolvers:
Key Features:
- Dependencies Resolution: Converts version constraints from Pipfile 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
- Dependency Groups: Supports both default packages and dev-packages sections
- Complex Constraint Handling: Supports version ranges, Git dependencies, and environment markers
Resolution Workflow:
- Detects
Pipfilein your project (whenPipfile.lockis not present) - Auto-detects available resolver (
uvorpip-tools) in current environment - Resolves version constraints to exact dependency versions
- Scans resolved dependencies for vulnerabilities
- Reports findings with dependency group classification
Note: When both Pipfile and Pipfile.lock are present, PySentry prioritizes the lock file for better accuracy. Consider using pipenv lock to generate a lock file for the most precise vulnerability scanning.
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:
- Detects
requirements.txtfiles in your project - Auto-detects available resolver (
uvorpip-tools) in current environment - Resolves version constraints to exact dependency versions
- Scans resolved dependencies for vulnerabilities
- Reports findings with direct vs. transitive classification
Environment Setup:
# Ensure resolver is available in your environment
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 (
uvorpip-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
PySentry uses all three vulnerability sources by default for comprehensive coverage.
PyPA Advisory Database
- 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.
Markdown
GitHub-friendly format with structured sections and severity indicators. Perfect for documentation, GitHub issues, and security reports.
JSON
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 from multiple sources
- Multi-tier Caching: Intelligent caching for both vulnerability data and resolved dependencies
- Efficient Matching: In-memory indexing for fast vulnerability lookups
- Streaming: Large databases processed without excessive memory usage
Resolution Cache Performance
The resolution cache provides dramatic performance improvements for requirements.txt files:
- First scan: Standard resolution time using
uvorpip-tools - Subsequent scans: Near-instantaneous when cache is fresh (>90% time savings)
- Cache invalidation: Automatic when requirements content, resolver, or environment changes
- Content-aware: Different cache entries for different Python versions and platforms
Requirements.txt Resolution Performance
PySentry leverages external resolvers with intelligent caching:
- 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
- Resolution caching: Eliminates repeated resolver calls for unchanged requirements
Development
Building from Source
Running Tests
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
# Or specify the path explicitly
Error: "No dependency resolver found" or "uv resolver not available"
# Install a supported resolver in your environment
# Verify resolver is available
# If using virtual environments, ensure resolver is installed there
Error: "Failed to resolve requirements"
# Check your requirements.txt syntax
# Try different resolver
# Ensure you're in correct environment
# Debug with verbose output
Error: "Failed to fetch vulnerability data"
# Check network connectivity
# Try with different or multiple sources
# For slow or unstable networks, increase timeout and retries
# Create/edit .pysentry.toml in your project:
[]
= 300 # 5 minute timeout
= 5 # More retry attempts
= 120 # Longer backoff delays
# Then run again
Network timeout errors:
PySentry includes automatic retry with exponential backoff for network issues. If you still experience timeouts:
# Increase timeout values in config
# Edit .pysentry.toml and adjust [http] section
Rate limiting (HTTP 429 errors):
PySentry automatically handles rate limiting. If rate limits persist:
[]
= 5 # More attempts
= 5 # Longer initial wait
= 300 # Up to 5 minute backoff
Slow requirements.txt resolution
# Use faster uv resolver instead of pip-tools
# Install uv for better performance (2-10x faster)
# Or use uvx for isolated execution
Requirements.txt files not being detected
# Ensure requirements.txt exists
# Specify path explicitly
# Include additional requirements files
# Check if higher-priority files exist (they take precedence)
Performance Issues
# Clear all caches and retry
# Clear only resolution cache (if vulnerability cache is working)
# Clear resolution cache via CLI
# Use verbose mode to identify bottlenecks
# Disable caching to isolate issues
Resolution Cache Issues
# Clear stale resolution cache after environment changes
# Disable resolution cache if causing issues
# Extend cache TTL for stable environments
# Check cache usage with verbose output
# Force fresh resolution (ignores cache)