/hep-python-tools:standalone-scriptfrom hep-python-tools
Generates self-contained Python scripts with PEP 723 inline dependency metadata, runnable via uv run --script. Use for one-off analysis tools or single-file utilities that declare their own dependencies.
Ships in hep-python-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
PEP 723 (Python 3.12+, backported via uv) lets a .py file declare its own
dependencies in a # /// script comment block. Running the script with
uv run --script <file> automatically installs deps into a temporary
environment. This is the right pattern for one-off analysis scripts, quick
tools, and anything you want to share as a single file.
pip install instructions)hep-python-tools:cli-creator for a proper CLI layerrequirements.txt + python script.py workflow| Concept | Notes |
|---|---|
# /// script block | Top-level comment block; by convention placed near the top |
requires-python | Minimum Python version for the script |
dependencies | PEP 508 dependency specs — same syntax as pyproject.toml |
uv run --script <file> | Installs deps and runs in one step |
uv lock --script <file> | Write a <file>.lock adjacent to the script |
uv run --script --frozen <file> | Use the existing lock without re-resolving (needs .lock) |
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "uproot>=5",
# "awkward>=2",
# "hist>=2.7",
# "vector>=1",
# "typer>=0.9",
# "mplhep",
# ]
# ///
"""Fetch jet pT from a local ROOT file and plot a histogram."""
from __future__ import annotations
from pathlib import Path
from typing import Annotated
import awkward as ak
import hist
import mplhep
import matplotlib.pyplot as plt
import typer
import uproot
import vector
vector.register_awkward()
mplhep.style.use("ATLAS")
app = typer.Typer()
@app.command()
def main(
root_file: Annotated[Path, typer.Argument(help="Input ROOT file", exists=True)],
tree: Annotated[str, typer.Option(help="TTree name")] = "reco",
output: Annotated[Path, typer.Option(help="Output plot")] = Path("jet_pt.pdf"),
) -> None:
"""Plot jet pT distribution from ROOT_FILE."""
with uproot.open(root_file) as f:
jets = f[tree].arrays(["jet_pt", "jet_eta"], library="ak")
selected = jets[ak.num(jets.jet_pt) >= 1]
pts = ak.to_numpy(ak.flatten(selected.jet_pt)) / 1000 # MeV → GeV
h = hist.Hist(hist.axis.Regular(50, 0, 500, name="pt", label=r"$p_T$ [GeV]"))
h.fill(pt=pts)
fig, ax = plt.subplots()
h.plot1d(ax=ax)
ax.set_ylabel("Events")
fig.savefig(output)
typer.echo(f"Saved: {output}")
if __name__ == "__main__":
app()
Run it:
uv run --script my_analysis.py data.root --output jet_pt.pdf
For testing with a specific tree:
uv run --script my_analysis.py data.root --tree reco
For reproducibility in scripts that will be shared or run in CI:
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "uproot==5.3.9",
# "awkward==2.6.5",
# ]
# ///
Or generate a lockfile once and run frozen in CI. --frozen reuses the lock and
errors if analysis.py.lock is missing, so you must uv lock --script first:
uv lock --script analysis.py # writes analysis.py.lock (commit it)
uv run --script --frozen analysis.py input.root
# /// script block to be a top-level comment block (every
line starts at column 0); it does not have to precede imports or the module
docstring. uv scans the whole file for it. Place it near the top (after an
optional shebang) for readability. There must be exactly one script
block, or tools error.# (or be a
bare #). A line that does not start with # ends the block.uv run --script re-resolves when there is no lock: For repeatable CI
runs, uv lock --script once (commit the .lock) then run with --frozen,
which reuses the lock instead of re-resolving.uv run <file>: --script flag tells uv to treat the
file as a PEP 723 script; without it, uv runs the file in the current
project's virtualenv.requires-python constraint is enforced — if your
system Python is older, uv downloads a matching interpreter automatically (if
using uv with Python management enabled).#!/usr/bin/env -S uv run --script as
the first line for a truly self-running script on Unix.assets/pep723_typer_script.py as a starting
template (PEP 723 header + a minimal Typer app with a -v/ --verbose count
option already wired to logging level).uv run --script is the primary runner; also works with pixi runpixi run python script.py works if deps are in the pixi
environment; PEP 723 is not needed in that caseWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub usatlas/marketplace --plugin hep-python-tools6 skills in this plugin
/cli-creatorUse when building a Python command-line interface with Typer: adding arguments and options to a script, creating subcommands, wiring an entry point into pyproject.toml, validating CLI inputs with callbacks, or adding a CLI layer to an existing analysis script or HEP workflow./code-quality-toolsUse when setting up code quality tooling for a HEP Python project: configuring pre-commit hooks, adding ruff for linting and auto-formatting, setting up mypy for static type checking, or debugging linter failures in CI or a pre-commit run./pytest-speedupUse when a pytest suite is slow and needs speeding up: profiling slow tests, reducing collection time, parallelizing with pytest-xdist or pytest-split, selecting a subset of tests to run, blocking inadvertent network or large-file disk access in HEP tests, or optimizing CI test run time.