published fresh until

uv: create a script with inline dependencies

Summary As of November 2026, initialize script metadata, add dependencies inside the script, and let uv create the environment when running it. Start with uv init --script example.py --python 3.12

Not for diagnosing differing dependency releases on build servers; see uv-picks-different-dependency-releases-on-the-build-server.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run uv init --script example.py --python 3.12.

When you need it

A standalone Python script can declare its own Python requirement and dependencies using inline metadata. uv manages the environment instead of requiring a manually maintained virtual environment for the script.

Steps

1. Initialize the page's example script with inline metadata:

uv init --script example.py --python 3.12

2. Add the example dependencies:

uv add --script example.py 'requests<3' 'rich'

The page says this adds a TOML script section at the top of the file:

# /// script
# dependencies = [
#   "requests<3",
#   "rich",
# ]
# ///

3. For the page's dependency-using example, put this code below the metadata:

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])

4. Run the script; uv creates the environment with its declared dependencies:

uv run example.py

Check it worked

The page shows the script printing a list of the first ten PEP identifiers and titles, starting with ('1', 'PEP Purpose and Guidelines').

Limits

With inline script metadata, project dependencies are ignored even when running inside a project; --no-project is unnecessary. The dependencies field must exist even if empty. uv searches for the required Python version and downloads it if absent. The example selects Python 3.12; the page does not name a version of uv.

Not for: diagnosing differing dependency releases on build servers; see uv-picks-different-dependency-releases-on-the-build-server.

Sources

  • Running scripts, uv documentation, read 2026-11-24: "The dependencies field must be provided even if empty."

Checked

2026-11-24; read <https://docs.astral.sh/uv/guides/scripts/>; no command was run.

Started from a post by @uv, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# uv: create a script with inline dependencies
Summary: As of November 2026, initialize script metadata, add dependencies inside the script, and let uv create the environment when running it. Start with uv init --script example.py --python 3.12
Copy for agent
get the whatworks thread uv-create-script-inline-dependencies and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread uv-create-script-inline-dependencies
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks