Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 38 ยท Dependency Management

Updating and Auditing Dependencies

Keep Python dependencies current and safe with outdated checks, pip-audit, Dependabot and Renovate, and learn to read vulnerability advisories with working code.

A lock file freezes your dependencies in time, which is great for reproducibility and terrible for security if you never look at it again. Libraries get bug fixes, new Python versions drop support for old releases, and sometimes a vulnerability is found in a version you pinned two years ago. Healthy projects treat updates as a routine chore rather than a yearly emergency.

This lesson covers the routine: finding what is outdated, deciding how big each upgrade is, scanning for known vulnerabilities, and automating the work.

Finding outdated packages

Every tool can tell you what has a newer release:

Terminal
pip list --outdated            # pip
uv pip list --outdated         # uv's pip interface
uv lock --upgrade-package requests   # move one package forward
poetry show --outdated         # Poetry
pdm outdated                   # PDM

The output compares the installed (locked) version with the latest allowed one. The size of the jump tells you how careful to be. With versions that follow semantic versioning, a patch (2.31.0 to 2.31.1) fixes bugs, a minor (2.31 to 2.32) adds features, and a major (2.x to 3.0) may break compatibility. Not every project follows that convention, so read changelogs for anything beyond a patch.

Python Classify available upgrades

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

(Version numbers only hint at risk: attrs uses calendar versions, so its "major" jump above is not necessarily a break.) A sensible routine is to take all patch and minor updates together in one batch (the test suite is your safety net), and to handle each major update on its own so a failure points to one cause.

Safe upgrade workflow

  1. Create a branch. Upgrade a small group of packages, or one major.
  2. Regenerate the lock file (uv lock --upgrade, pip-compile --upgrade, poetry update).
  3. Run the full test suite and the type checker. Warnings are early hints: run pytest with -W error::DeprecationWarning for one pass to see what the next major release will remove.
  4. Skim the changelog of anything that changed more than a patch.
  5. Merge, deploy, and keep the previous lock file available in version control for rollback.

If an upgrade breaks something you cannot fix right now, pin the offending package with an exclusion in pyproject.toml (for example somepkg!=4.0.0 or somepkg<4) and write a comment saying why. An undocumented ceiling lives forever.

Security auditing

Public databases record vulnerabilities with an identifier (such as a PYSEC or GHSA id or a CVE), the affected version ranges, and the version that fixes them. An auditing tool compares your lock file with those records:

Terminal
pip install pip-audit
pip-audit                          # audit the current environment
pip-audit -r requirements.txt      # audit a requirements file
pip-audit --fix                    # try upgrading vulnerable packages

pip-audit queries the Python Packaging Advisory Database (and can use OSV). GitHub's Dependabot alerts and commercial scanners do similar work. Run an audit in CI so a new advisory turns a build red, and schedule it weekly, because advisories appear even when your code does not change.

The check itself is simple: is my pinned version inside a vulnerable range? That is a job for specifier sets:

Python Check pins against an advisory list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real databases are not fictional, of course, but the logic is the same. Two practical notes: a vulnerability in a package does not always mean your code is exploitable (the vulnerable function may be unused), but you should still upgrade or document why you did not; and if no fixed version exists, consider replacing the package.

Automating updates

Humans forget, bots do not. Two popular bots open pull requests when new versions appear:

  • Dependabot (built into GitHub) reads pyproject.toml, requirements files and many lock files.
  • Renovate supports many platforms and has detailed grouping and scheduling rules.

A minimal Dependabot configuration, saved as .github/dependabot.yml:

YAML
version: 2
updates:
  - package-ecosystem: "pip"
    directory: "/"
    schedule:
      interval: "weekly"
    groups:
      minor-and-patch:
        update-types: ["minor", "patch"]

The groups entry batches minor and patch updates into one pull request, which keeps the noise down. Each pull request runs your CI; if tests pass, merging is a quick decision. For uv projects, Dependabot and Renovate both understand uv.lock.

More habits that reduce risk

  • Know what you depend on. pipdeptree (read-only here) prints the tree; fewer dependencies mean fewer advisories.
  • Prefer maintained packages. Look at release dates and open issues before adding something new.
  • Beware of typosquatting. Names such as reqeusts can be malicious. Copy install commands from the project's own documentation.
  • Use hashes and trusted indexes (see lock files).
  • Keep Python itself current. Old interpreters stop receiving security fixes, and libraries drop support for them.
  • Remove what you no longer use. Unused dependencies still get scanned and still appear in advisories.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which upgrade should you review most carefully?

    A major version may contain breaking changes by convention, so read its changelog and upgrade it separately from routine updates.
  2. 2. What does pip-audit compare?

    It looks up each package version in an advisory database and reports matches with the version that fixes them.
  3. 3. Why should an audit also run on a schedule, not only when code changes?

    A dependency can become known-vulnerable overnight without any change in your repository.
  4. 4. What is a good practice when you must cap a dependency to avoid a broken release?

    Documented ceilings can be removed when the issue is fixed; silent ones stay forever and hide the real problem.

Summary

  • Check for outdated packages regularly; patch and minor updates can be batched, major updates handled one at a time.
  • Upgrade on a branch, regenerate the lock, run tests and read changelogs.
  • pip-audit and similar tools match your versions against advisory databases; run them in CI and on a schedule.
  • Dependabot or Renovate automate update pull requests.
  • Fewer, well-maintained dependencies are easier to keep safe.

Next: Linting with Ruff and Pyflakes