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 run --with gives a python one-off its own temporary packages

Python
~/tips/tip-python-uv-run-with

uv run --with requests python -c "import requests; print(requests.__version__)"

Runs python with extra packages in a disposable environment, without installing them anywhere permanent.

Sometimes I only need requests for one quick check and do not want a venv for it.

uv run --with requests python -c "import requests; print(requests.__version__)"
uv run --with httpx --with rich python script.py

--with adds a package to a throwaway environment that uv builds from its cache and discards after the command, so nothing lands in your global site-packages. Repeat the flag for more packages. Inside a project directory the project’s own dependencies are included as well. The first run downloads the packages, later runs reuse the cache and start quickly. It is a quick way to test a library on a clean setup.

Further reading: uv documentation: running scripts

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