uv learning notes
Table of contents
features
python versions
installing and managing python:
uv python install: install python versionuv python list: view all available python versionsuv python find: find an installed python versionuv python pin: pin the current project to use a specific python versionuv python uninstall:
scripts
executing standalone python scripts, like example.py:
uv run: run a scriptuv add --script: add a dependency to a scriptuv remove --script: remove a dependency from a script
projects
uv init: create a new python projectuv add: add a dependency to the projectuv remove: remove a dependency from the projectuv sync: sync the project’s dependencies with the environmentuv lock: create a lockfileuv run: run a command in the project environuv tree: view dependency tree for the projectuv build: build the project into distribution archivesuv publish: publish the project
tools
uv tool run: run a tool in a temporary environmentuv tool install: install a tool use-wideuv tool uninstall: uninstall a tooluv tool list: list installed toolsuv tool update-shell: update the shell to include tool executables.
guides
scripts
without dependency:
import sys
print("".join(sys.argv[1:]))
uv run example.py test
# not depend on the project
uv run --no-project example.py
with dependency:
uv run --with rich example.py
creating a python script
uv init --script example.py --python 3.12
declare script dependencies
uv add --script example.py 'requests<3' 'rich'
alternative package indexes
uv add --index "https" --script example.py 'rich'
locking dependency
uv lock --script example.py