Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pip-audit

> 包管理
Open source

Audits Python environments, requirements files and dependency trees for known security vulnerabilities, and can automatically fix them

1.3K stars0 likes3 views
WebsiteGitHub

About

Audits Python environments, requirements files and dependency trees for known security vulnerabilities, and can automatically fix them

pip-audit

pip-audit is a tool for scanning Python environments for packages with known vulnerabilities. It uses the Python Packaging Advisory Database (https://github.com/pypa/advisory-database) via the PyPI JSON API as a source of vulnerability reports.

This project was created by Trail of Bits with support from Google, and is currently maintained under the Python Packaging Authority. This is not an official Google or Trail of Bits product.

Index

  • Features
  • Installation
    • Third-party packages
    • GitHub Actions
    • pre-commit support
  • Usage
    • Environment variables
    • Exit codes
    • Dry runs
  • Examples
  • Troubleshooting
  • Tips and Tricks
  • Security model
  • Licensing
  • Contributing
  • Code of Conduct

Features

  • Support for auditing local environments and requirements-style files
  • Support for multiple vulnerability services (PyPI, OSV)
  • Support for emitting SBOMs in CycloneDX XML or JSON
  • Support for automatically fixing vulnerable dependencies (--fix)
  • Human and machine-readable output formats (columnar, Markdown, JSON)
  • Seamlessly reuses your existing local pip caches

Installation

pip-audit requires Python 3.10 or newer, and can be installed directly via pip:

bash
python -m pip install pip-audit

Third-party packages

There are multiple third-party packages for pip-audit. The matrices and badges below list some of them:

In particular, pip-audit can be installed via conda:

bash
conda install -c conda-forge pip-audit

Third-party packages are not directly supported by this project. Please consult your package manager's documentation for more detailed installation guidance.

GitHub Actions

pip-audit has an official GitHub Action!

You can install it from the GitHub Marketplace, or add it to your CI manually:

yaml
jobs:
  pip-audit:
    steps:
      - uses: pypa/[email protected]
        with:
          inputs: requirements.txt

See the action documentation for more details and usage examples.

pre-commit support

pip-audit has pre-commit support.

For example, using pip-audit via pre-commit to audit a requirements file:

yaml
  - repo: https://github.com/pypa/pip-audit
    rev: v2.10.1
    hooks:
      -   id: pip-audit
          args: ["-r", "requirements.txt"]

ci:
  # Leave pip-audit to only run locally and not in CI
  # pre-commit.ci does not allow network calls
  skip: [pip-audit]

Any pip-audit arguments documented below can be passed.

Usage

You can run pip-audit as a standalone program, or via python -m:

bash
pip-audit --help
python -m pip_audit --help
…

Environment variables

pip-audit allows users to configure some flags via environment variables instead:

Flag Environment equivalent Example
--format PIP_AUDIT_FORMAT PIP_AUDIT_FORMAT=markdown
--vulnerability-service PIP_AUDIT_VULNERABILITY_SERVICE PIP_AUDIT_VULNERABILITY_SERVICE=osv
--desc PIP_AUDIT_DESC PIP_AUDIT_DESC=off
--progress-spinner PIP_AUDIT_PROGRESS_SPINNER PIP_AUDIT_PROGRESS_SPINNER=off
--output PIP_AUDIT_OUTPUT PIP_AUDIT_OUTPUT=/tmp/example

Exit codes

On completion, pip-audit will exit with a code indicating its status.

The current codes are:

  • 0: No known vulnerabilities were detected.
  • 1: One or more known vulnerabilities were found.

pip-audit's exit code cannot be suppressed. See Suppressing exit codes from pip-audit for supported alternatives.

Dry runs

pip-audit supports the --dry-run flag, which can be used to control whether an audit (or fix) step is actually performed.

  • On its own, pip-audit --dry-run skips the auditing step and prints the number of dependencies that would have been audited.
  • In fix mode, pip-audit --fix --dry-run performs the auditing step and prints out the fix behavior (i.e., which dependencies would be upgraded or skipped) that would have been performed.

Examples

Audit dependencies for the current Python environment:

bash
$ pip-audit
No known vulnerabilities found

Audit dependencies for a given requirements file:

bash
$ pip-audit -r ./requirements.txt
No known vulnerabilities found

Audit dependencies for a requirements file, excluding system packages:

bash
$ pip-audit -r ./requirements.txt -l
No known vulnerabilities found

Audit dependencies for a local Python project:

bash
$ pip-audit .
No known vulnerabilities found

Audit lockfiles for a local Python project:

bash
$ pip-audit --locked .
No known vulnerabilities found

pip-audit searches the provided path for various Python "project" files. At the moment, only pyproject.toml and pylock.*.toml are supported.

Audit dependencies when there are vulnerabilities present:

bash
$ pip-audit
Found 2 known vulnerabilities in 1 package
Name  Version ID             Fix Versions
----  ------- -------------- ------------
Flask 0.5     PYSEC-2019-179 1.0
Flask 0.5     PYSEC-2018-66  0.12.3

Audit dependencies including aliases:

bash
$ pip-audit --aliases
Found 2 known vulnerabilities in 1 package
Name  Version ID             Fix Versions Aliases
----  ------- -------------- ------------ -------------------------------------
Flask 0.5     PYSEC-2019-179 1.0          CVE-2019-1010083, GHSA-5wv5-4vpf-pj6m
Flask 0.5     PYSEC-2018-66  0.12.3       CVE-2018-1000656, GHSA-562c-5r94-xh97

Audit dependencies including descriptions:

…

Audit dependencies in JSON format:

…

Audit and attempt to automatically upgrade vulnerable dependencies:

bash
$ pip-audit --fix
Found 2 known vulnerabilities in 1 package and fixed 2 vulnerabilities in 1 package
Name  Version ID             Fix Versions Applied Fix
----- ------- -------------- ------------ ----------------------------------------
flask 0.5     PYSEC-2019-179 1.0          Successfully upgraded flask (0.5 => 1.0)
flask 0.5     PYSEC-2018-66  0.12.3       Successfully upgraded flask (0.5 => 1.0)

Troubleshooting

Have you resolved a problem with pip-audit? Help us by contributing to this section!

pip-audit shows irrelevant vulnerability reports!

In a perfect world, vulnerability feeds would have an infinite signal-to-noise ratio: every vulnerability report would be (1) correct, and (2) applicable to every use of every dependency.

Unfortunately, neither of these is guaranteed: vulnerability feeds are not immune to extraneous or spam reports, and not all uses of a particular dependency map to all potential classes of vulnerabilities.

If your pip-audit runs produce vulnerability reports that aren't actionable for your particular application or use case, you can use the --ignore-vuln ID option to ignore specific vulnerability reports. --ignore-vuln supports aliases, so you can use a GHSA-xxx or CVE-xxx ID instead of a PYSEC-xxx ID if the report in question does not have a PYSEC ID.

For example, here is how you might ignore GHSA-w596-4wvx-j9j6, which is a common source of noisy vulnerability reports and false positives for users of pytest:

bash
# Run the audit as normal, but exclude any reports that match GHSA-w596-4wvx-j9j6
$ pip-audit --ignore-vuln GHSA-w596-4wvx-j9j6

The --ignore-vuln ID option works with all other dependency resolution and auditing options, meaning that it should function correctly with requirements-style inputs, alternative vulnerability feeds, and so forth.

It can also be passed multiple times, to ignore multiple reports:

bash
# Run the audit as normal, but exclude any reports that match these IDs
$ pip-audit --ignore-vuln CVE-XXX-YYYY --ignore-vuln CVE-ZZZ-AAAA

pip-audit takes longer than I expect!

Depending on how you're using it, pip-audit may have to perform its own dependency resolution, which can take roughly as long as pip install does for a project. See the security model for an explanation.

You have two options for avoiding dependency resolution: audit a pre-installed environment, or ensure that your dependencies are already fully resolved.

If you know that you've already fully configured an environment equivalent to the one that pip-audit -r requirements.txt would audit, you can simply reuse it:

bash
# Note the absence of any "input" arguments, indicating that the environment is used.
$ pip-audit

# Optionally filter out non-local packages, for virtual environments:
$ pip-audit --local

Alternatively, if your input is fully pinned (and optionally hashed), you can tell pip-audit to skip dependency resolution with either --no-deps (pinned without hashes) or --require-hashes (pinned including hashes).

The latter is equivalent to pip's hash-checking mode and is preferred, since it offers additional integrity.

bash
# fails if any dependency is not fully pinned
$ pip-audit --no-deps -r requirements.txt

# fails if any dependency is not fully pinned *or* is missing hashes
$ pip-audit --require-hashes -r requirements.txt

pip-audit can't authenticate to my third-party index!

Authenticated third-party or private indices

pip-audit supports --index-url and --extra-index-url for configuring an alternate or supplemental package indices, just like pip.

When unauthenticated, these indices should work as expected. However, when a third-party index requires authentication, pip-audit has a few additional restrictions on top of ordinary pip:

  • Interactive authentication is not supported. In other words: pip-audit will not prompt you for a username/password for the index.
  • pip's keyring authentication is supported, but in a limited fashion: pip-audit uses the subprocess keyring provider, since audits happen in isolated virtual environments. The subprocess provider in turn is subject to additional restrictions (such as a required username); pip's documentation explains these in depth.

In addition to the above, some third-party indices have required, hard-coded usernames. For example, for Google Artifact registry, the hard-coded username is oauth2accesstoken. See #742 and pip#11971 for additional context.

Tips and Tricks

Running against a pipenv project

`pi

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonpippythonsecuritysecurity-audit

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image