Description
What's the problem this feature will solve?
This feature request represents support for installing the requirements of a single-file script with inline metadata (PEP 723) using pip
.
Pessimistically assuming that this feature request is rejected, this issue is also being filed as a home for a specific record of the maintainer rationale for not including this functionality in pip
.
Describe the solution you'd like
I am imagining functionality that would be similar to the existing --requirement
argument, with a suitably distinct name to indicate that the metadata format is the one defined by PEP 723 and the living PyPA spec.
Perhaps something like:
$ cat standalone_script.py
# /// 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])
$ pip install --script standalone_script.py
...
Where the pip install
invocation is equivalent to pip install "requests<3" "rich"
if the requires-python
bound is satisfied
Alternative Solutions
I know that other tools¹ in the Python packaging ecosystem do support PEP 723, but these tools are not "included batteries" nearly as often as pip
is. In my estimation, supporting in-line metadata in pip
will improve the experience of many users (especially non-programmers) who just want to run a script they've been given and are starting with a "typical" bare Python environment.
¹non-exhaustive list: pipx, hatch, pip-run
Additional context
The reference implementation for parsing inline metadata seems to be enough to retrieve the list of requirements from a file. I imagine that the result of this can be plumbed into existing machinery used for satisfying dependencies listed in requirements files.
It's worth mentioning that there is a potential argument for allowing multiple scripts to be parsed and installed from in a single pip
invocation (in the same way that --requirement
can be given multiple times). I think it makes sense but I can see why there might be some reluctance about doing it since it is more or less directly against the grain of the primary "single script" use-case of inline metadata.
Code of Conduct
- I agree to follow the PSF Code of Conduct.