linkedin / linkedin/shiv

Support PEP-723 Style in-line metadata annotated scripts

Open
#266 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
114
PR merge metrics
No merged PRs in 30d

Description

[PEP-723](https://peps.python.org/pep-0723) describes how to add comments to a script to specify what its dependencies should be similar to a `pyproject.toml`. The [Python Packaging Docs](https://packaging.python.org/en/latest/specifications/inline-script-metadata) give more information and include future updates to the spec.

`example.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])
```

[uv](https://docs.astral.sh/uv/guides/scripts/#declaring-script-dependencies) supports running the above script directly with `uv run example.py`. The downside with this is that each time you run it with uv it will make calls to the network to ensure its on the correct versions of the packages each time. Fine for development, less so for production use cases.

It would be nice if `shiv` could do something similar like `shiv --inline-script example.py --output-file example` to make a portable script that needs no network requirement.

Contributor guide

Open the contributing guide

Research direction

Start by examining shiv's existing command-line entry point and packaging flow, then use the issue's example.py and proposed `shiv --inline-script example.py --output-file example` invocation as the behavior to support. Done means a PEP-723-style script can be packaged into a portable artifact without requiring network access at runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.