Skip to content

python component reference ​

This page lists every field and option. The overview shows what it does and a first example.

The python component runs a Python script in a managed virtualenv and returns its stdout, parsed as JSON when possible and as raw text otherwise.

It is a kdeps component from the components asset set. Call it with a component: resource. You do not install it. It calls the python tool of the kdeps API. This tool runs the native Python executor. kdeps rejects a workflow that uses python: directly, as primary or in a before:/after: step.

It runs as a workflow step.

component: pythonPOST /tools/python/calluv venvversion + packagespython -c scriptor python scriptFilestdout parsed as JSONelse raw text

Configuration ​

yaml
# resources/analyze.yaml
actionId: analyze
name: Analyze Data
component:
  name: python                     # from the components asset set
  with:
    script: |                      # inline Python; print JSON for structured output
      import json
      print(json.dumps({"rows": 3}))
    timeout: 120s                  # hard stop; the call fails after it, no retry
InputTypeRequiredDefaultDescription
scriptstringone of script / scriptFile-Inline Python source
scriptFilestringone of script / scriptFile-Path to a .py file; relative paths resolve against the kdeps process working directory
argsarrayno-Arguments passed to the script after the script path or -c
envobjectno-Extra environment variables; the process environment is inherited
timeoutstringnoKDEPS_PYTHON_TIMEOUT, else the kdeps defaultHard stop for the script (e.g. 30s, 2m)
venvNamestringnopackage-hashed default venvDedicated virtualenv name; resources sharing a name share packages
pythonVersionstringnoKDEPS_PYTHON_VERSION, else 3.12Interpreter version for the venv
packagesarrayno-Python packages installed into the venv before the script runs

Script or script file ​

script runs inline through python -c. scriptFile runs a file on disk and receives args through sys.argv:

yaml
# resources/process.yaml
actionId: process
component:
  name: python
  with:
    scriptFile: "./scripts/data_processor.py"
    args: ["--mode", "analyze", "--data", "{{ get('data') }}"]
python
# scripts/data_processor.py
import argparse
import json

parser = argparse.ArgumentParser()
parser.add_argument("--mode", required=True)
parser.add_argument("--data", required=True)
args = parser.parse_args()

print(json.dumps({"status": "success", "mode": args.mode}))

Packages and virtualenvs ​

kdeps manages Python with uv. Packages go in the call, not in workflow settings:

yaml
# resources/report.yaml
actionId: report
component:
  name: python
  with:
    packages: ["pandas>=2.0", "requests"]   # installed into the venv on first run
    script: |
      import pandas as pd
      print(pd.__version__)

kdeps builds the venv one time and uses it again. Without venvName, kdeps makes the name from the package list. As a result, two resources with the same packages use one venv. Give a venvName to isolate a resource from everything else:

yaml
# resources/data-science.yaml
component:
  name: python
  with:
    venvName: "datascience-env"
    packages: ["pandas", "numpy"]

# resources/html-tools.yaml -- separate venv, separate package set
component:
  name: python
  with:
    venvName: "html-env"
    packages: ["requests", "beautifulsoup4"]

Output ​

The script's stdout is the resource output. When stdout parses as a JSON object, the resource output is that object. Otherwise it is the raw text.

yaml
# resources/summarize.yaml
actionId: summarize
component:
  name: python
  with:
    script: |
      import json
      print(json.dumps({"status": "success", "data": [1, 2, 3]}))
yaml
flow:
  # resources/response.yaml
  requires: [summarize]
apiResponse:
  success: true
  response:
    full: get('summarize')          # the parsed map
    status: get('summarize').status
    data: get('summarize').data

A non-zero exit does not return stdout: the call fails with python execution failed: ..., stderr: ... and onError: on the resource decides what happens next. stderr and the exit code stay in the logs.

Environment variables ​

env: sets variables for that one call. Values are expressions. kdeps evaluates them on each run. Give secrets this way, not in args:. All users on the machine can read args: in the process list:

yaml
# resources/fetch.yaml
actionId: fetch
component:
  name: python
  with:
    env:
      DB_PASSWORD: "{{ env('DB_PASSWORD') }}"
    script: |
      import os
      print(os.environ["DB_PASSWORD"] != "")

The script gets the workflow values from runtime.env:

yaml
# In workflow.yaml
deploy:
  runtime:
    env:
      API_KEY: "secret-key"
      DEBUG: "true"
python
import os

api_key = os.environ.get('API_KEY')
debug = os.environ.get('DEBUG') == 'true'
VariableEffect
KDEPS_PYTHON_VERSIONDefault pythonVersion when the call does not set one (then 3.12)
KDEPS_PYTHON_TIMEOUTDefault timeout when the call does not set one
KDEPS_PYTHON_MAX_OUTPUT_BYTESCap on captured stdout; exceeding it fails the call

Errors and timeouts ​

ErrorCause
python: script or scriptFile is requiredNeither script nor scriptFile was given
python execution failed: ..., stderr: ...The script exited non-zero; stderr is quoted in the message
python stdout exceeds output limit of N bytesOutput crossed KDEPS_PYTHON_MAX_OUTPUT_BYTES
failed to ensure venv: ...uv could not build the virtualenv (bad version, network, package resolution)

To handle a script that fails and not stop the workflow, use onError::

yaml
# resources/optional-step.yaml
actionId: optionalStep
component:
  name: python
  with:
    script: |
      raise SystemExit(3)
flow:
  onError:
    action: continue

See also ​

kdeps has the Apache 2.0 License.