brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: uv tree shows why a python package is in your project

Python
~/tips/tip-python-uv-tree-invert

uv tree --depth 1

See your project's dependency tree and which package pulled in a library.

In a project managed with uv, uv tree draws the dependency tree from the lock file. The inverted view is the one I find most useful.

uv tree --depth 1
uv tree --invert --package idna

The first command lists only your direct dependencies with their locked versions. The second answers “why is this installed at all?” by turning the tree upside down:

idna v3.20
└── requests v2.34.2
    └── myproject v0.1.0

That’s how you find out a library nobody asked for comes in through requests, before you try to remove it or pin it. Add --outdated and uv also marks packages that have a newer version available, which is a quick way to see what an upgrade would touch.

uv may update the lock file before it prints, the same way uv run would. If you want to look without any chance of that, add --frozen and it reads uv.lock exactly as it is. Without a pyproject.toml there’s nothing to show, so for a plain venv with pip you’d need pip show and its Required-by line instead.

Further reading: uv tree reference

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link