Python runs

A Python run executes a script with python3. The script is the run's command. It suits a task that is more comfortable in Python than a shell: calling an API, reconciling state, or shaping data.

What runs

The script is written to a temporary file and run with python3, so multi-line scripts work unchanged. The working directory is the project checkout when the run sources a project. A dry run runs python3 -I -m py_compile, which checks syntax in Python's isolated mode, so no file in the project is imported and the script is not executed.

How values reach the script

Example

import json, os, urllib.request
vars = json.loads(os.environ.get("SWITCHTENDER_VARS", "{}"))
token = os.environ["SWITCHTENDER_TOKEN"]
req = urllib.request.Request(
    f"https://api.example.com/deploy/{vars['service']}",
    headers={"Authorization": f"Bearer {token}"}, method="POST")
print(urllib.request.urlopen(req).status)

See also Bash runs, Terraform runs, Go runs, and the tutorials.