Transform a Python script into a self-contained uv script by adding PEP 723 inline metadata (# /// script block) with auto-detected dependencies and requires-python. Handles existing blocks idempotently.
Transform the target Python script into a self-contained, uv-executable script by adding or updating the PEP 723 # /// script inline metadata block.
Use $ARGUMENTS as the file path. If empty, use the file open or selected in the current conversation context. If still unclear, ask the user to specify the path.
Read the full content of the target .py file.
Scan every line for import statements and collect top-level module names:
import X → module is Ximport X as Y → module is Xfrom X.Y.Z import ... → module is X (first segment only)Skip lines that are inside triple-quoted strings (""" / ''') or that are themselves comments ().
#Do NOT list these as dependencies. Exclude any module in this set:
__future__, abc, argparse, ast, asyncio, base64, builtins, calendar, cmath, cmd, code, codecs, collections, concurrent, configparser, contextlib, copy, csv, ctypes, dataclasses, datetime, decimal, difflib, email, enum, errno, fileinput, fnmatch, fractions, ftplib, functools, gc, getopt, getpass, glob, gzip, hashlib, heapq, hmac, html, http, imaplib, importlib, inspect, io, ipaddress, itertools, json, keyword, linecache, locale, logging, math, mimetypes, multiprocessing, operator, os, pathlib, pickle, platform, pprint, queue, random, re, shlex, shutil, signal, socket, socketserver, sqlite3, ssl, stat, statistics, string, struct, subprocess, sys, tarfile, tempfile, textwrap, threading, time, timeit, tkinter, traceback, types, typing, unicodedata, unittest, urllib, uuid, warnings, weakref, xml, xmlrpc, zipfile, zlib
Use the table below. For any module not listed, use the import name verbatim as the package name, and append a # NOTE: verify package name comment on that line.
| Import name | PyPI package |
|---|---|
anthropic | anthropic |
bs4 | beautifulsoup4 |
cv2 | opencv-python |
dateutil | python-dateutil |
dotenv | python-dotenv |
flask | flask |
django | django |
httpx | httpx |
jwt | PyJWT |
matplotlib | matplotlib |
numpy | numpy |
openai | openai |
pandas | pandas |
PIL | Pillow |
pkg_resources | setuptools |
psutil | psutil |
psycopg2 | psycopg2-binary |
pydantic | pydantic |
pymongo | pymongo |
pytest | pytest |
redis | redis |
requests | requests |
rich | rich |
sklearn | scikit-learn |
scipy | scipy |
sqlalchemy | SQLAlchemy |
toml | toml |
tomllib | (stdlib in Python ≥3.11 — skip entirely) |
tqdm | tqdm |
typer | typer |
yaml | PyYAML |
requires-pythonInspect the script for the highest version signal found:
| Signal | Minimum version |
|---|---|
match / case statement | >=3.10 |
X | Y type union in annotations | >=3.10 |
typing.Self or typing.LiteralString | >=3.11 |
tomllib import (stdlib) | >=3.11 |
Walrus operator := | >=3.8 |
f-string = specifier (f"{x=}") | >=3.8 |
Positional-only param / in def | >=3.8 |
| No signals detected | >=3.11 (default) |
Use the highest version constraint found.
# /// script blockSearch the script for an existing block matching:
# /// script
...
# ///
If found: Extract its current dependencies and requires-python values. Merge the detected dependencies with any already listed (union, no duplicates). If the newly determined requires-python is higher than the existing one, use the higher version. Replace the existing block in-place.
If not found: Insert a new block (see Step 9).
Check line 1:
#!/usr/bin/env -S uv run → leave unchanged#!/usr/bin/env python3) → replace with #!/usr/bin/env -S uv run and note the change in your report#!/usr/bin/env -S uv runThe output file must have this structure:
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=X.Y"
# dependencies = [
# "package-a",
# "package-b",
# ]
# ///
<rest of original script, byte-for-byte identical>
Rules:
# /// script block immediately follows (one blank line between shebang and block is acceptable but not required).requires-python comes before dependencies inside the block."package",.# /// from the first line of the original script body.Write the composed content back to the same file path.
Output a concise summary: