Scan dependencies for known vulnerabilities and licenses.
npx @tessl/cli install tessl/pypi-safety@3.6.0Safety CLI is a comprehensive vulnerability scanning tool for Python dependencies that helps developers identify and fix security vulnerabilities in their projects. It scans Python packages for known security vulnerabilities, licenses issues, and provides automated fixes.
pip install safetysafety3.6.1safety.cli:cli# Scan current project for vulnerabilities
safety scan
# Legacy check command (deprecated but still available)
safety check
# Check for license issues
safety license
# Authenticate with Safety platform
safety auth login
# Get help
safety --help# Import the main CLI function
from safety.cli import cli
# Import core models and utilities
from safety.models import (
Vulnerability, CVE, Severity, Fix,
SafetyRequirement, Package, RequirementFile
)
# Import scanning functionality
from safety.scan.main import process_files
from safety.scan.finder import FileFinder
# Import formatters
from safety.formatters.json import JsonReport
from safety.formatters.text import TextReportSafety provides comprehensive vulnerability scanning capabilities for Python projects:
Primary Scanning Commands:
safety scan [OPTIONS] [TARGET] # Scan project dependencies
safety system-scan [OPTIONS] # Scan system packages
safety check [OPTIONS] [FILES] # Legacy vulnerability check
safety license [OPTIONS] [FILES] # License compliance checkSafety integrates with the Safety platform for enhanced vulnerability data and organizational features:
Authentication Commands:
safety auth login # Authenticate with Safety platform
safety auth logout # Sign out
safety auth status # Check authentication status
safety auth register # Register new accountMultiple output formats and reporting options:
Output Format Options:
--output json # JSON format
--output text # Plain text
--output html # HTML report
--save-as FILE # Save report to filefrom safety.models import Vulnerability, CVE, Severity
# Core vulnerability information
class Vulnerability:
vulnerability_id: str
package_name: str
vulnerable_spec: str
advisory: str
published_date: datetime
fixed_versions: List[str]
CVE: CVE
severity: Severity
# CVE information
class CVE:
name: str
cvssv2: Optional[float]
cvssv3: Optional[float]
# Severity assessment
class Severity:
source: str
cvssv2: Optional[float]
cvssv3: Optional[float]from safety.models import Package, SafetyRequirement
# Package metadata
class Package:
name: str
version: str
requirements: List[SafetyRequirement]
# Enhanced requirement with safety features
class SafetyRequirement(Requirement):
raw: str # Original requirement line
found: Optional[str] # Where requirement was found
def to_dict(self) -> Dict # Convert to dictionaryfrom safety_schemas.models import ConfigModel, Ecosystem, Stage
# Main configuration
class ConfigModel:
telemetry_enabled: bool
# Supported ecosystems
class Ecosystem(Enum):
PYTHON = "python"
# Development stages
class Stage(Enum):
DEVELOPMENT = "development"
PRODUCTION = "production"# Scan current directory
safety scan
# Scan specific path
safety scan /path/to/project
# Scan with JSON output
safety scan --output json# Login to Safety platform
safety auth login
# Check authentication status
safety auth status
# Scan with authenticated access
safety scan# Generate policy template
safety generate policy
# Scan with policy file
safety scan --policy-file .safety-policy.yml
# Generate installation policy
safety generate installation_policy# Check licenses in requirements file
safety license --files requirements.txt
# Check with custom database
safety license --db /path/to/license_dbThis documentation provides comprehensive coverage of Safety CLI's public API for developers who need to integrate vulnerability scanning into their workflows, whether through command-line usage or programmatic access.