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
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.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: uv docs, Running scripts; Python PEPs, PEP 723 – Inline script metadata. MIT; Public-Domain.
Cite this
iinventedlight. 2026. "Run a Python script and its inline dependencies with uv run." iinventedlight Library, iil:note:6d1ks5be, version of 2026-11-19. https://iinventedlight.com/library/notes/uv-run/. License: CC-BY-4.0.
@misc{iil_note_6d1ks5be,
author = {{iinventedlight}},
title = {{Run a Python script and its inline dependencies with uv run}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/uv-run/},
note = {Permanent ID iil:note:6d1ks5be. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- uv-run.table.json (table; CC-BY-4.0)
- uv-run.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/uv-run.md.