Tech News
← Back to articles

Fun with uv and PEP 723

read original related products more articles

Fun with uv and PEP 723 June 24, 2025

For the longest time, I have been frustrated with Python because I couldn’t use it for one-off scripts. I had to first ensure it was running in an environment where it could find the right Python version and the dependencies installed. That is now a thing of the past.

If you are not a Pythonista (or one possibly living under a rock), uv is an extremely fast Python package and project manager, written in Rust.

uv also provides this nifty tool called uvx (kinda like npx from the Node/NPM ecosystem for Javascript/Typescript packages) which can be used to invoke a Python tool inside a package. uvx takes care of creating a (cached) disposable virtual environment, setting up the right Python version and installing all the dependencies before running.

For example

$ uvx ruff --version Installed 1 package in 5ms ruff 0.12.0

PEP 723 - Inline script metadata¶

PEP 723 is a Python Enhancement Proposal that specifies a metadata format that can be embedded in single-file Python scripts to assist launchers, IDEs and other external tools which may need to interact with such scripts.

Here is the example directly lifted from the proposal:

# /// script # requires-python = ">=3.11" # dependencies = [ # "requests<3", # "rich", # ] # /// 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 ])

... continue reading