Guides / Languages and packages

Audit Python dependencies with pip-audit

beginnerUpdated 26 Nov 20261022 words

pip-audit, from the Python Packaging Authority (PyPA), reads a requirements file, a lock file or a project and lists the packages with known vulnerabilities, each with the version that fixes it. Run it before a deploy and on a schedule.

Install it

The current version in November 2026 is 2.10.1, which needs Python 3.10 or later. Install it in an environment of its own:

pipx install pip-audit

or in a virtual environment:

python3 -m venv ~/.venvs/pip-audit
~/.venvs/pip-audit/bin/pip install pip-audit

pip-audit has dependencies of its own that can clash with those of the app: in a test with an app that pins requests==2.25.0, pip refused to install pip-audit next to it (ResolutionImpossible).

On Debian 12 and later, pip install into the system Python stops with error: externally-managed-environment (PEP 668). Use pipx (apt install pipx) or a virtual environment as above.

Audit a requirements file

pip-audit -r requirements.txt

For a file with the single line requests==2.25.0 (trimmed; in this run each advisory appeared twice in the table, and the count includes the repeats):

Found 24 known vulnerabilities in 3 packages
Name     Version ID              Fix Versions
-------- ------- --------------- ------------
requests 2.25.0  PYSEC-2023-74   2.31.0
requests 2.25.0  PYSEC-2026-1873 2.32.0
requests 2.25.0  PYSEC-2026-1872 2.32.4
requests 2.25.0  PYSEC-2026-2275 2.33.0
idna     2.10    PYSEC-2024-60   3.7
idna     2.10    PYSEC-2026-215  3.15
urllib3  1.26.20 PYSEC-2026-1999 2.5.0
...
urllib3  1.26.20 PYSEC-2026-4175 2.8.0

idna and urllib3 are not in the file. pip-audit resolves a requirements file the way pip install -r would and audits the whole result. Its documentation treats this as equivalent to installing: do not audit a requirements file from an untrusted source that you would not pip install either.

The IDs come from the Python Packaging Advisory Database (PYSEC-…). -f json shows the aliases: PYSEC-2023-74 is CVE-2023-32681, the leak of Proxy-Authorization headers on redirects in requests.

Pinned files with hashes

If every line is pinned with a hash, pip-audit audits the file as it is, without resolving anything:

uv pip compile --generate-hashes requirements.in -o requirements.txt
pip-audit --require-hashes --disable-pip -r requirements.txt

pip-compile --generate-hashes from pip-tools and uv export write the same format.

Audit the environment of a running app

To audit what is installed on the server, including packages someone added by hand, write the list from the environment of the app and audit it as pinned requirements:

/srv/myapp/.venv/bin/pip freeze > /tmp/myapp-frozen.txt
pip-audit --no-deps --disable-pip -r /tmp/myapp-frozen.txt

--no-deps skips the resolution; pip freeze already lists every installed package with its version. You can ignore the warning that hashed requirements are preferred.

Audit a project with pyproject.toml

From the project directory:

pip-audit .

pip-audit resolves the dependencies of pyproject.toml. With --locked, it reads the pylock.*.toml lock files of PEP 751 instead (pip lock . writes one; the pip documentation marks the command as experimental). For a uv.lock, export a hashed requirements file and audit that:

uv export --format requirements-txt --no-emit-project > requirements.txt
pip-audit --require-hashes --disable-pip -r requirements.txt

Exit codes and CI

The exit code is 0 when pip-audit finds nothing and 1 when it finds a vulnerability. According to the documentation, a flag cannot suppress it; append || true to report without failing. --strict also fails the run when pip-audit cannot collect a dependency, so a gap in the audit shows up as a failure.

The PyPA GitHub Action, with a schedule that finds advisories published on days without commits:

name: pip-audit
on:
  push:
  pull_request:
  schedule:
    - cron: "23 6 * * *"
jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: pypa/gh-action-pip-audit@v1.1.0
        with:
          inputs: requirements.txt

In GitLab CI:

pip-audit:
  image: python:3.13-slim
  script:
    - pip install pip-audit==2.10.1
    - pip-audit --strict -r requirements.txt

Fix findings

--fix --dry-run shows what pip-audit would upgrade:

pip-audit --fix --dry-run -r requirements.txt
INFO:pip_audit._cli:Dry run: would have upgraded requests to 2.33.0
INFO:pip_audit._cli:Dry run: would have upgraded idna to 3.15
INFO:pip_audit._cli:Dry run: would have upgraded urllib3 to 2.8.0

If you compile your requirements with pip-tools or uv, upgrade the package in the lock step, then install, test and audit again:

pip-compile --upgrade-package requests requirements.in
uv lock --upgrade-package requests

Both move only the package you name, and only within the constraint of requirements.in or pyproject.toml: with requests==2.25.0 in requirements.in, nothing changes. In the test, --upgrade-package requests took requests from 2.25.0 to 2.34.2 and left idna 2.10 and urllib3 1.26.20 with their advisories. Name each package from the report (--upgrade-package idna --upgrade-package urllib3) or run a full --upgrade (uv lock --upgrade).

To raise a vulnerable package that only comes in as a dependency of a dependency, use a constraints file (pip install -c constraints.txt) or constraint-dependencies in the [tool.uv] table, until the package in the middle requires the fixed version itself.

Ignore a finding

Some advisories cover a feature you do not use. Ignore them by ID, and write down why next to the command in your CI file:

pip-audit -r requirements.txt --ignore-vuln CVE-2023-32681

The PYSEC ID works, and so do its CVE and GHSA aliases.

Where the data comes from

By default pip-audit asks the PyPI JSON API, which lists known vulnerabilities for each release from the Python Packaging Advisory Database. -s osv asks the OSV database instead; in the test it found 26 entries where PyPI gave 24. Both requests contain the names and versions of your packages.

Python packages installed with apt, dnf or apk (python3-requests and the like) belong to the operating system and get their fixes through the security updates of the distribution.

The Vulnpocalypse agent reads the requirements and lock files of the app paths you configure, and Vulnpocalypse checks them against new advisories every day.

Sources

Check your servers every day

The Vulnpocalypse agent reports the packages and settings of a server once a day, and the digest lists what to fix, most urgent first.

Start free