Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Installation¶
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="/usr/local/bin" sh
curl -LsSf https://astral.sh/uv/install.sh | sudo env UV_INSTALL_DIR="/usr/local/bin" shUsage¶
Run Executable Scripts of Python Packages¶
Run
python -m http.serverto start a simple http server.uvx python -m http.serverRun the ruff tool.
uvx ruff -hRun
snbfrom the aiutil package.uvx --from aiutil snb -h
Ad-hoc Python Shell & Scripts¶
You can start an ad-hoc Python shell ( e.g., Python 3.14 with 3rd-party packages dockeree and aituil ) using the following command.
uv run --python 3.13 --with dockeree --with aiutil pythonSimilar to the above but start an IPython shell instead.
uv run --python 3.13 --with dockeree --with aiutil --with IPython python -m IPythonInitialize a uv managed Python script.
uv init --python 3.14 --script example.pyNotice that if the script
example.pyalready exists, uv will just append metadata lines into it.You can add dependencies to a uv managed Python scripts using the following command.
uv add --script example.py 'requests<3' 'rich'You can run a uv managed Python script using
uv run /path/to/uv_managed_script.pyor
# preferred uv run --script /path/to/uv_managed_script.pyThose 2 commands will automatically resolve and install dependencies specified in the script. This can be simplified by add the shebang
#!/usr/bin/env -S uv runor#!/usr/bin/env -S uv run --scriptinto the Python script, so that you can invoke the script as an executable directly.You might want to pass Python interpretor options (e.g., the
-Poption) while running a script usinguv. This can be done using the command below.uv run python -P /path/to/uv_managed_script.pyHowever, it has one drawback. It doesn’t automatically resolve and install dependencies specified in the script. Luckily, with PR merged, this is possible through the option
--with-requirements script_with_deps.pywhich includes inline dependency metadata fromscript_with_deps.py. So, you can use the following command (though it’s verbose).uv run python -P /path/to/uv_managed_script.py --with-requirements uv_managed_script.py
Manage Projects¶
Migrate from other Python projects to uv.
uvx migrate-to-uvInitialize a new uv project with the given name.
uv init --package new_project_nameInitialize the current project as a uv project.
uv init --packageUpdate the lock file (changing as little as possible).
uv lockUpdate the lock file ensuring that dependencies are the newest version allowed by the spec.
uv lock --upgradeCreate a virtual environment if one doesn’t already exist and install all dependencies.
uv syncInstall all dependencies including optional ones.
uv sync --all-extrasInstall all dependencies but not the current project.
uv sync --no-install-projectBuild the project.
uv buildPublish the project.
uv publish