From 0b053cadc30ecf0398ce7999b348619a148dd309 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 20 Aug 2024 08:50:22 -0500 Subject: [PATCH] Add script support to feature highlights in index --- docs/getting-started/features.md | 2 ++ docs/index.md | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/features.md b/docs/getting-started/features.md index 3019cc332194..3429bad9629a 100644 --- a/docs/getting-started/features.md +++ b/docs/getting-started/features.md @@ -22,6 +22,8 @@ See the [guide on installing Python](../guides/install-python.md) to get started Executing standalone Python scripts, e.g., `example.py`. - `uv run`: Run a script. +- `uv add --script`: Add a dependency to a script +- `uv remove --script`: Remove a dependency from a script See the [guide on running scripts](../guides/scripts.md) to get started. diff --git a/docs/index.md b/docs/index.md index 50fe12eefda9..e85ff6f662c7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,7 +20,7 @@ An extremely fast Python package and project manager, written in Rust. - ⚡️ [10-100x faster](https://github.com/astral-sh/uv/blob/main/BENCHMARKS.md) than `pip`. - 🐍 [Installs and manages](#python-management) Python versions. - 🛠️ [Runs and installs](#tool-management) Python applications. -- ❇️ [Runs scripts](./guides/scripts.md), with support for +- ❇️ [Runs scripts](#script-support), with support for [inline dependency metadata](./guides/scripts.md#declaring-script-dependencies). - 🗂️ Provides [comprehensive project management](#project-management), with a [universal lockfile](./concepts/projects.md#lockfile). @@ -158,6 +158,30 @@ Pinned `.python-version` to `pypy@3.11` See the [installing Python guide](./guides/install-python.md) to get started. +### Script support + +uv manages dependencies and environments for single-file scripts. + +Create a new script and add inline metadata declaring its dependencies: + +```console +$ echo 'import requests; print(requests.get("https://astral.sh"))' > example.py + +$ uv add --script example.py requests +Updated `example.py` +``` + +Then, run the script in an isolated virtual environment: + +``` +$ uv run example.py +Reading inline script metadata from: example.py +Installed 5 packages in 12ms + +``` + +See the [scripts guide](./guides/scripts.md) to get started. + ## The pip interface uv provides a drop-in replacement for common `pip`, `pip-tools`, and `virtualenv` commands.