Safety CLI (safety) is a Python dependency vulnerability scanner that identifies known security vulnerabilities and malicious packages in your project's dependencies. It integrates into local development, CI/CD pipelines, and production systems, providing actionable remediation recommendations. The current version is 3.7.0, and it maintains an active release cadence with regular updates.
pip install safetyNo compatibility data collected yet for this library.
This quickstart demonstrates how to programmatically run `safety scan` using Python's `subprocess` module to check a `requirements.txt` file. It includes a dummy vulnerable dependency (requests==2.25.1) to show output with findings. For comprehensive vulnerability data, an API key might be required, which can be passed via `SAFETY_API_KEY` environment variable or configured using `safety auth`.
Migrate your `safety` policy files to the new schema introduced in Safety CLI 3. For details, refer to the official Safety documentation on migrating from Safety 2.x to Safety CLI 3.
Update your scripts and CI/CD pipelines to use `safety scan` instead of `safety check`. The `scan` command offers improved functionality and native support for various project types.
Review and update any custom parsers or scripts that consume Safety's JSON output to align with the new JSON structure. Refer to the official documentation for the updated schema.
If license scanning is critical, consider pinning to an older Safety 2.x version or exploring alternative tools until license support is fully integrated into the `safety scan` command.
Register for a Safety account and obtain an API key. Use `safety auth` to log in, or pass the API key via the `--key` option or `SAFETY_API_KEY` environment variable for automated environments.
Ensure your Python environment is version 3.9 or higher before installing or upgrading Safety CLI to the latest version.
pip install safety (or pipx install safety for an isolated installation).
Provide your API key using the `--api-key` flag or by setting the `SAFETY_API_KEY` environment variable: `safety scan --api-key YOUR_API_KEY` or `export SAFETY_API_KEY="YOUR_API_KEY" && safety scan`.
Specify the path to your requirements file after the `-r` or `--file` option: `safety scan -r requirements.txt`.
Verify that `pip` is correctly installed and functional in your current environment by running `pip list`. Consider reinstalling `pip` or using a fresh virtual environment.
No dependency data recorded yet.