Guides / Languages and packages

Audit Python dependencies with pip-audit

beginnerUpdated 26 Nov 20261082 words

pip-audit is the dependency auditor of the Python Packaging Authority (PyPA). It takes a requirements file, a lock file or a project and reports the packages with known vulnerabilities, with the version that fixes each one. Run it before a deploy and on a schedule for every Python app you keep on a server.

Install it

As of November 2026 the current version is 2.10.1, which needs Python 3.10 or later. Install it in its own environment so that its dependencies do not mix with those of your app:

pipx install pip-audit

or in a virtual environment:

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

Keep it out of the environment of the app. pip-audit has its own dependencies, and 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 describes this as equivalent to installing: if you would not pip install a requirements file from an untrusted source, do not audit it 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 can audit 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 see 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, which is right here because pip freeze lists every installed package with its version. pip-audit prints a warning that hashed requirements are preferred; for this use you can ignore it.

Audit a project with pyproject.toml

From the project directory:

pip-audit .

This resolves the dependencies of pyproject.toml. With --locked, pip-audit 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

pip-audit exits with 0 when it finds nothing and with 1 when it finds a vulnerability. The documentation states that the exit code cannot be suppressed by a flag; to report without failing, append || true. --strict also fails the run when a dependency cannot be collected, so that a gap in the audit does not pass silently.

The PyPA GitHub Action:

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

The scheduled run finds advisories published on days without commits.

Fix findings

The table gives the first fixed version for each finding. --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 in place. Name each package from the report (--upgrade-package idna --upgrade-package urllib3) or run a full --upgrade (uv lock --upgrade).

A vulnerable package that only arrives as a dependency of a dependency can be raised with a constraints file (pip install -c constraints.txt) or with 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 from the distribution, through its security updates.

The Patchbrief agent can read the requirements and lock files of the app paths you configure and checks them against new advisories every day.

Sources

Check your servers every day

The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.

Start free