---
source: https://iinventedlight.com/library/notes/uv-run.md
title: "Run a Python script and its inline dependencies with uv run"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (uv docs); Public-Domain (Python PEPs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: uv docs, Running scripts; Python PEPs, PEP 723 – Inline script metadata. MIT; Public-Domain."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: uv run and PEP 723 inline script metadata"
tags: [python, uv, pep-723, scripts, dependencies]
client: Librarian
sources:
  - id: S1
    title: "Running scripts"
    publisher: uv docs
    url: https://docs.astral.sh/uv/guides/scripts/
    accessed: 2026-11-19
    license: "MIT"
  - id: S2
    title: "PEP 723 – Inline script metadata"
    publisher: Python PEPs
    url: https://peps.python.org/pep-0723/
    accessed: 2026-11-19
    license: "Public-Domain"
---
# Run a Python script and its inline dependencies with uv run
**Answer:** A Python script is a file intended for standalone execution, for example with `python <script>.py`. uv manages script dependencies without manually managing environments. PEP 723 specifies a metadata format that can be embedded in single-file Python scripts.

## Running and locking

`uv run` is the usual way to execute the script in that managed environment. Scripts can declare dependencies with inline metadata. They can also be locked: running `uv lock --script` will create a `.lock` file adjacent to the script (for example, `example.py.lock`). Unlike with projects, scripts must be explicitly locked using `uv lock`.

## Why the metadata exists

Python is routinely used as a scripting language. Launchers, IDEs and other external tools may need to interact with such scripts, including their dependencies. Launchers, IDEs and other external tools may need to interact with such scripts.

| uv run | PEP 723 |
|---|---|
| uv run | Execute a script with managed dependencies |
| inline metadata | Declares dependencies inside the script |
| uv lock --script | Creates a .lock file adjacent to the script |
| PEP 723 | Metadata format for single-file Python scripts |

## See also

- [uv-index](https://iinventedlight.com/library/notes/uv-index/)
- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)
- [python-venv](https://iinventedlight.com/library/notes/python-venv/)

## Claims

- id: C1
  claim: uv execute scripts so script dependencies are managed without manually managing environments.
  source: S1
  evidence: "script dependencies are managed without manually managing environments"

- id: C2
  claim: Scripts can also be locked with uv lock --script, which creates an adjacent lock file.
  source: S1
  evidence: "Running uv lock --script will create a .lock file adjacent to the script"

- id: C3
  claim: PEP 723 specifies a metadata format that can be embedded in single-file Python scripts.
  source: S2
  evidence: "a metadata format that can be embedded in single-file Python scripts"

## Sources

- [S1] Running scripts. uv docs. https://docs.astral.sh/uv/guides/scripts/ . License: MIT. Accessed 2026-11-19.

- [S2] PEP 723 – Inline script metadata. Python PEPs. https://peps.python.org/pep-0723/ . License: Public-Domain. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: uv docs, Running scripts; Python PEPs, PEP 723 – Inline script metadata. MIT; Public-Domain. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
