Skip to main content

Run self-contained uv Python scripts as callable, schema-documented 'superpowers'.

Project description

supypowers

Run self-contained Python scripts (with uv script dependencies) as callable, schema-documented functions.

What you can do with this

  • Run a typed function in a script: validate/coerce JSON input with Pydantic, execute, emit JSON output.
  • Generate documentation for all scripts in a folder as either JSON (for machines/LLMs) or Markdown (for humans).

Prerequisites

  • uv must be installed and on your PATH (the CLI shells out to uv run).

Install

pip install supypowers

If you prefer installing via uv tools (to get a global supypowers command without a venv), see “Install supypowers on your PATH”.

Quickstart

Try the bundled examples:

supypowers docs examples --format md
supypowers run examples exponents:compute_sqrt "{'x': 9}"

Initialize a new supypowers/ folder with starter templates (hello.py + hello.md):

supypowers init .

If you don’t have the supypowers command on your PATH yet, you can always run it via uv from this repo:

uv run supypowers docs examples --format md
uv run supypowers run examples exponents:compute_sqrt "{'x': 9}"

Core concepts

Script dependencies (per-script, no venv)

Each script declares its dependencies using uv inline script metadata:

# /// script
# dependencies = [
#   "pydantic",
# ]
# ///

Supypowers reads those dependencies and runs your function in an isolated uv run environment (it does not import your script into the CLI process).

Superpower function contract

A function is considered a “supypower” if it matches this contract:

  • Exactly one parameter, named input
  • The input type is a Pydantic BaseModel
  • Input data is validated/coerced via Pydantic (it must be an object mapping)
  • Output can be any type; if it’s a Pydantic model, it will be emitted in JSON-friendly form

See examples/exponents.py for the canonical pattern.

Running functions

Syntax

supypowers run <folder> <script>:<function> <input_data> [--secrets ...]

Input format (<input_data>)

  • Preferred: strict JSON (e.g. {"x": 9})
  • Also supported (“YAML-ish”): Python literal objects (e.g. {'x': 9}) via ast.literal_eval

Supypowers will then validate/coerce that object into your Pydantic model.

Secrets (--secrets)

You can pass secrets as:

  • a dotenv file path (e.g. --secrets .env)
  • inline KEY=VAL pairs (e.g. --secrets API_KEY=abc)

They are exposed to your script via environment variables.

Examples

supypowers run examples exponents:compute_sqrt "{'x': 9}"
supypowers run examples strings:reverse_string "{'s': 'abc'}"
supypowers run examples dates:add_days "{'d': '2025-01-01', 'days': 10}"
supypowers run examples exponents:compute_sqrt "{'x': 9}" --secrets .env --secrets API_KEY=abc

Generating documentation

JSON docs (for machines / LLM context)

supypowers docs <folder> --format json
supypowers docs <folder> --format json --output docs.json

The JSON output is a list of:

  • script: path to the script
  • functions: list of functions with name, description, input_schema, output_schema
  • error (optional): if a script failed to load/inspect

Markdown docs (for humans)

supypowers docs <folder> --format md
supypowers docs <folder> --format md --output docs.md

Options

  • --recursive: recurse into subfolders and include **/*.py
  • --require-marker: only include functions explicitly marked (currently: decorator named superpower)

Install supypowers on your PATH (so you can run supypowers ...)

If you don’t want to prefix every command with uv run, install the CLI as a uv “tool”:

Use uv tool install:

cd /Users/andre/ergodic/superpowers
uv tool install --editable .
uv tool update-shell

Then open a new shell (or reload your shell config) and run:

supypowers docs examples
supypowers run examples exponents:compute_sqrt \"{'x': 9}\"

Example scripts

See examples/ (uses uv script metadata + Pydantic models).

Troubleshooting

  • uv not found: install uv and ensure it’s on your PATH.
  • Docs command returns errors for a script: run uv run <script.py> yourself to verify the script’s dependencies/imports are valid.
  • Input validation errors: ensure you pass an object mapping with keys matching your input model fields.

Notes (implementation)

  • The CLI executes target scripts only via uv run <script.py> ... (no imports into the CLI process).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supypowers-0.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supypowers-0.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file supypowers-0.1.1.tar.gz.

File metadata

  • Download URL: supypowers-0.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for supypowers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 71611e4035e4edcc2e2fb4d5b738a34f270e28e26b0ea2ec321d41388a426749
MD5 c443ff9135a117029eea34f38d547844
BLAKE2b-256 8bfe7c783e7cee64c52169716d3db895596015369eaebe7e5c637845f09dbc68

See more details on using hashes here.

File details

Details for the file supypowers-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: supypowers-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for supypowers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d68f536951ae66e69797cb5cef607a197590691b3e1b878a1968de66f5f221ab
MD5 a71e5c33c0aa1f48fab5b523232747eb
BLAKE2b-256 b565c672599c8073f37affd7ebfbbb4bbff6b96d09770ce3105760638c1facae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page