Standalone Python Scripts with uv

VerifiedSafe

Create standalone Python scripts using uv shebang with PEP 723 inline metadata. Automatically manage dependencies without a full project setup.

Sby Skills Guide Bot
DevelopmentIntermediate
7/23/2026
Claude CodeCursorWindsurfCodex
#uv#python#single-file-script#pep723#cli

Recommended for

Automated summary

This skill guides the creation of standalone single-file Python scripts run through the uv shebang, using PEP 723 inline metadata to declare dependencies.

Strengths

  • Provides a complete template with uv shebang, PEP 723 block, and a main() entry point returning an exit code
  • Explains how to declare dependencies and minimum Python version directly inside the file
  • Covers best practices: errors to stderr, argparse or typer, modern type hints
  • Specifies file placement conventions for a chezmoi-managed dotfiles repository

Limitations

  • Assumes uv is installed and on the PATH without describing installation
  • Does not address multi-file projects or conventional virtual environments
  • The file placement section is specific to chezmoi and not broadly generalizable
When to use it

Use it when building a throwaway or distributable single-file Python tool that must manage its own dependencies without a full project setup.

When not to use it

Avoid it when the code belongs to an existing Python project with pyproject.toml and a venv, or when the user explicitly asks to integrate with the project environment.

Security analysis

Safe
Quality score88/100

The skill only provides guidance and templates for writing standalone Python scripts with uv/PEP 723 metadata. Declared tools are limited to Read, Write, and Glob, with no destructive commands, credential access, network exfiltration, obfuscation, or safety-disabling instructions.

No concerns found

How this analysis is made

Examples

Dependency-declaring script
Create a single-file Python script that fetches a URL and pretty-prints the JSON, using uv shebang and PEP 723 inline metadata for requests and rich.
CLI tool with typer
Write a standalone Python CLI tool that converts CSV files to JSON, using uv run --script with inline dependencies including typer.
chezmoi script placement
Create a one-file Python utility for my dotfiles repo and place it as dot_scripts/executable_<name> so chezmoi manages it.

name: uv-script description: Create standalone Python scripts using uv shebang with PEP 723 inline metadata. Use when creating single-file Python tools or scripts that need dependency management without a full project setup. allowed-tools: Read, Write, Glob

uv Shebang Python Script

Pythonで単体スクリプトを作成する際に使用するスキル。

発火条件

  • Pythonで単体スクリプト(単一ファイルで完結するツール)を作成するとき
  • 発火させたくない場合はユーザーが明示的に伝える(例:「プロジェクトのvenv使うのでuv単体スクリプトにしないで」)

テンプレート

#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""スクリプトの説明."""

import argparse
import sys


def main() -> int:
    parser = argparse.ArgumentParser(description="スクリプトの説明")
    parser.add_argument("arg", help="引数の説明")
    args = parser.parse_args()

    # メイン処理

    return 0


if __name__ == "__main__":
    sys.exit(main())

構成要素

シェバン

#!/usr/bin/env -S uv run --script

-S オプションで複数引数を渡す。これによりuvが依存関係を自動解決して実行する。

PEP 723 インラインメタデータ

# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "requests>=2.28",
#     "rich",
# ]
# ///
  • TOMLコメント形式で依存関係を宣言
  • requires-python: 最小Pythonバージョン(3.11以上推奨)
  • dependencies: pipの要件指定形式で依存パッケージを列挙

エントリーポイント

def main() -> int:
    # 処理
    return 0  # 終了コード

if __name__ == "__main__":
    sys.exit(main())
  • main() は終了コードを返す(成功: 0、失敗: 1)
  • sys.exit() で終了コードを伝播

ベストプラクティス

エラー出力

print("Error: something went wrong", file=sys.stderr)
return 1

エラーメッセージは標準エラー出力へ。

引数処理

シンプルな場合は argparse、複雑なCLIは typer を依存に追加:

# dependencies = ["typer"]

型ヒント

Python 3.11+の型ヒント構文を使用:

def process(items: list[str]) -> dict[str, int]:
    ...

ファイル配置

dotfilesリポジトリの場合:

  • dot_scripts/executable_<name> として配置
  • chezmoi適用後 ~/.scripts/<name> として利用可能

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/standalone-python-scripts-with-uv-mrx3xxh6/download' --output '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md.part' && mv '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md.part' '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Write, Glob

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md' && test -s '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/uv-script' && cp -R '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6' '.claude/skills/uv-script'

Cursor
test -f '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md' && test -s '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/uv-script' && cp -R '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6' '.cursor/skills/uv-script'

Codex
test -f '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md' && test -s '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/uv-script' && cp -R '.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6' '.agents/skills/uv-script'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6'

openskills read 'standalone-python-scripts-with-uv-mrx3xxh6'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/standalone-python-scripts-with-uv-mrx3xxh6/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills