← All notes

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

Sources

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

Permanent ID: iil:note:6d1ks5be

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.},
}

Markdown

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.

All artifact files (JSON index)

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.