diff --git a/docs/guides/scripts.md b/docs/guides/scripts.md index 82818b5f2..90816c9f9 100644 --- a/docs/guides/scripts.md +++ b/docs/guides/scripts.md @@ -217,6 +217,39 @@ print(Point) is not installed — see the documentation on [Python versions](../concepts/python-versions.md) for more details. +## Using a shebang to create an executable file + +A shebang can be added to make a script executable without using `uv run` — this makes it easy to +run scripts that are on your `PATH` or in the current folder. + +For example, create a file called `greet` with the following contents + +```python title="greet" +#!/usr/bin/env -S uv run --script + +print("Hello, world!") +``` + +Ensure that your script is executable, e.g., with `chmod +x greet`, then run the script: + +```console +$ ./greet +Hello, world! +``` + +Declaration of dependencies is also supported in this context, for example: + +```python title="example" +#!/usr/bin/env -S uv run --script +# /// script +# requires-python = ">=3.12" +# dependencies = ["httpx"] +# /// +import httpx + +print(httpx.get("https://example.com")) +``` + ## Using alternative package indexes If you wish to use an alternative [package index](../configuration/indexes.md) to resolve