CommandsCommands
CommandsCertified

yaml
type: "io.kestra.plugin.scripts.python.Commands"
yaml
id: python_venv
namespace: company.team

inputs:
  - id: nr
    type: INT
    defaults: 21

tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Commands
    namespaceFiles:
      enabled: true
      folderPerNamespace: true
      namespaces:
        - company
        - company.team
        - company.team.project # Explicitly name all namespaces to include; by default only the flow namespace is loaded.
      include:
        - etl_script.py
    taskRunner:
      type: io.kestra.plugin.core.runner.Process
    beforeCommands:
      - uv venv --python 3.13
      - uv pip install requests
    commands:
      - python etl_script.py --num {{inputs.nr}}

yaml
id: python_commands_example
namespace: company.team

tasks:
  - id: wdir
    type: io.kestra.plugin.core.flow.WorkingDirectory
    tasks:
      - id: clone_repository
        type: io.kestra.plugin.git.Clone
        url: https://github.com/kestra-io/examples
        branch: main

      - id: git_python_scripts
        type: io.kestra.plugin.scripts.python.Commands
        containerImage: ghcr.io/kestra-io/pydata:latest
        beforeCommands:
          - pip install faker > /dev/null
        commands:
          - python examples/scripts/etl_script.py
          - python examples/scripts/generate_orders.py
        outputFiles:
          - orders.csv

  - id: load_csv_to_s3
    type: io.kestra.plugin.aws.s3.Upload
    accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
    secretKeyId: "{{ secret('AWS_SECRET_KEY_ID') }}"
    region: eu-central-1
    bucket: kestraio
    key: stage/orders.csv
    from: "{{ outputs.gitPythonScripts.outputFiles['orders.csv'] }}"

yaml
id: gpu_task
namespace: company.team

tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Commands
    taskRunner:
      type: io.kestra.plugin.core.runner.Process
    commands:
      - python ml_on_gpu.py
    workerGroup:
      key: gpu

yaml
id: python_input_as_env_variable
namespace: company.team

inputs:
  - id: uri
    type: URI
    defaults: https://www.google.com/

tasks:
  - id: code
    type: io.kestra.plugin.scripts.python.Commands
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
    containerImage: ghcr.io/kestra-io/pydata:latest
    inputFiles:
      main.py: |
          import requests
          import os

          # Perform the GET request
          response = requests.get(os.environ['URI'])

          # Check if the request was successful
          if response.status_code == 200:
              # Print the content of the page
              print(response.text)
          else:
              print(f"Failed to retrieve the webpage. Status code: {response.status_code}")
    env:
      URI: "{{ inputs.uri }}"
    commands:
      - python main.py

yaml
id: s3_trigger_commands
namespace: company.team
description: process CSV file from S3 trigger

tasks:
  - id: wdir
    type: io.kestra.plugin.core.flow.WorkingDirectory
    tasks:
      - id: clone_repository
        type: io.kestra.plugin.git.Clone
        url: https://github.com/kestra-io/examples
        branch: main

      - id: python
        type: io.kestra.plugin.scripts.python.Commands
        inputFiles:
          data.csv: "{{ trigger.objects | jq('.[].uri') | first }}"
        description: this script reads a file `data.csv` from S3 trigger
        containerImage: ghcr.io/kestra-io/pydata:latest
        commands:
          - python examples/scripts/clean_messy_dataset.py
        outputFiles:
          - "*.csv"
          - "*.parquet"

triggers:
  - id: wait_for_s3_object
    type: io.kestra.plugin.aws.s3.Trigger
    bucket: declarative-orchestration
    maxKeys: 1
    interval: PT1S
    filter: FILES
    action: MOVE
    prefix: raw/
    moveTo:
      key: archive/raw/
    accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
    secretKeyId: "{{ secret('AWS_SECRET_KEY_ID') }}"
    region: "{{ secret('AWS_DEFAULT_REGION') }}"

yaml
id: python_in_container
namespace: company.team

tasks:
  - id: wdir
    type: io.kestra.plugin.core.flow.WorkingDirectory
    tasks:
      - id: clone_repository
        type: io.kestra.plugin.git.Clone
        url: https://github.com/kestra-io/examples
        branch: main

      - id: git_python_scripts
        type: io.kestra.plugin.scripts.python.Commands
        commands:
          - python examples/scripts/etl_script.py
        outputFiles:
          - "*.csv"
          - "*.parquet"
        containerImage: annageller/kestra:latest
        taskRunner:
          type: io.kestra.plugin.scripts.runner.docker.Docker
          config: |
            {
              "auths": {
                  "https://index.docker.io/v1/": {
                      "username": "annageller",
                      "password": "{{ secret('DOCKER_PAT') }}"
                  }
              }
            }

yaml
id: script_in_venv
namespace: company.team
tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Commands
    packageManager: UV
    inputFiles:
      main.py: |
        import requests
        from kestra import Kestra

        response = requests.get('https://google.com')
        print(response.status_code)
        Kestra.outputs({'status': response.status_code, 'text': response.text})
    beforeCommands:
      - python -m venv venv
      - . venv/bin/activate
      - pip install requests kestra > /dev/null
    commands:
      - python main.py
Properties
SubTypestring
SubTypestring
Defaultpython:3.13-slim
SubTypestring
Defaulttrue
SubTypestring
Defaulttrue
SubTypestring
Default["/bin/sh","-c"]
Definitions
enabledbooleanstring
Defaulttrue
excludearray
SubTypestring
folderPerNamespacebooleanstring
Defaultfalse
ifExistsstring
DefaultOVERWRITE
Possible Values
OVERWRITEFAILWARNIGNORE
includearray
SubTypestring
namespacesarray
SubTypestring
Default["{{flow.namespace}}"]
SubTypestring
DefaultUV
Possible Values
PIPUV
DefaultAUTO
Possible Values
LINUXWINDOWSAUTO
Definitions
type*Requiredobject
configstringobject
cpu
cpusnumberstring
credentials
authstring
identityTokenstring
passwordstring
registrystring
registryTokenstring
usernamestring
deletebooleanstring
Defaulttrue
deviceRequestsarray
capabilitiesarray
SubTypearray
countintegerstring
deviceIdsarray
SubTypestring
driverstring
optionsobject
SubTypestring
entryPointarray
SubTypestring
Default[ "" ]
extraHostsarray
SubTypestring
fileHandlingStrategystring
DefaultVOLUME
Possible Values
MOUNTVOLUME
hoststring
killGracePeriodstring
DefaultPT0S
Formatduration
memory
kernelMemorystring
memorystring
memoryReservationstring
memorySwapstring
memorySwappinessstring
oomKillDisablebooleanstring
networkModestring
portBindingsarray
SubTypestring
privilegedbooleanstring
pullPolicyobject
resumebooleanstring
Defaulttrue
shmSizestring
userstring
versionstring
volumesarray
SubTypestring
waitbooleanstring
Defaulttrue
type*Requiredobject
versionstring
region*Requiredstring
type*Requiredobject
bucketstring
completionCheckIntervalstring
DefaultPT5S
Formatduration
computeResource
bootDiskstring
cpustring
memorystring
deletebooleanstring
Defaulttrue
entryPointarray
SubTypestring
impersonatedServiceAccountstring
lifecyclePoliciesarray
actionstring
Possible Values
ACTION_UNSPECIFIEDRETRY_TASKFAIL_TASKUNRECOGNIZED
actionCondition
exitCodesarray
SubTypeinteger
machineTypestring
Defaulte2-medium
maxCreateJobRetryCountintegerstring
Default2
maxRetryCountinteger
Minimum>= 0
Maximum<= 10
networkInterfacesarray
network*Requiredstring
subnetworkstring
projectIdstring
reservationstring
resumebooleanstring
Defaulttrue
scopesarray
SubTypestring
Default["https://www.googleapis.com/auth/cloud-platform"]
serviceAccountstring
syncWorkingDirectorybooleanstring
Defaultfalse
versionstring
waitForLogIntervalstring
DefaultPT5S
Formatduration
waitUntilCompletionstring
DefaultPT1H
Formatduration
region*Requiredstring
type*Requiredobject
bucketstring
completionCheckIntervalstring
DefaultPT5S
Formatduration
deletebooleanstring
Defaulttrue
impersonatedServiceAccountstring
maxRetriesintegerstring
Default3
projectIdstring
resumebooleanstring
Defaulttrue
scopesarray
SubTypestring
Default["https://www.googleapis.com/auth/cloud-platform"]
serviceAccountstring
syncWorkingDirectorybooleanstring
versionstring
vpcAccessConnectorstring
vpcEgressstring
Possible Values
VPC_EGRESS_UNSPECIFIEDALL_TRAFFICPRIVATE_RANGES_ONLYUNRECOGNIZED
waitForLogIntervalstring
DefaultPT5S
Formatduration
waitUntilCompletionstring
DefaultPT1H
Formatduration
account*Requiredstring
endpoint*Requiredstring
poolId*Requiredstring
type*Requiredobject
accessKeystring
blobStorage
containerName*Requiredstring
connectionStringstring
endpointstring
sharedKeyAccountAccessKeystring
sharedKeyAccountNamestring
completionCheckIntervalstring
DefaultPT5S
Formatduration
deletebooleanstring
Defaulttrue
registry
identityReference
resourceIdstring
passwordstring
registryServerstring
userNamestring
resumebooleanstring
Defaulttrue
streamLogsbooleanstring
Defaultfalse
syncWorkingDirectorybooleanstring
Defaultfalse
versionstring
waitUntilCompletionstring
DefaultPT1H
Formatduration
type*Requiredobject
config
apiVersionstring
Defaultv1
caCertDatastring
caCertFilestring
clientCertDatastring
clientCertFilestring
clientKeyAlgostring
DefaultRSA
clientKeyDatastring
clientKeyFilestring
clientKeyPassphrasestring
disableHostnameVerificationbooleanstring
keyStoreFilestring
keyStorePassphrasestring
masterUrlstring
Defaulthttps://kubernetes.default.svc
namespacestring
oauthTokenstring
oauthTokenProvider
outputstring
task
passwordstring
trustCertsbooleanstring
trustStoreFilestring
trustStorePassphrasestring
usernamestring
containerDefaultSpecobject
containerSpecobject
deletebooleanstring
Defaulttrue
fileSideCarSpecobject
fileSidecar
Default{ "image": "busybox" }
defaultSpecobject
imagestring
Defaultbusybox
resourcesobject
killed
Defaultfalse
labelsobject
namespacestring
Defaultdefault
nodeSelectorobject
podSpecobject
pullPolicystring
DefaultALWAYS
Possible Values
IF_NOT_PRESENTALWAYSNEVER
resources
limit
cpustring
memorystring
request
cpustring
memorystring
resumebooleanstring
Defaulttrue
serviceAccountNamestring
syncWorkingDirectorybooleanstring
Defaultfalse
versionstring
waitForLogsstring
DefaultPT30S
Formatduration
waitUntilCompletionstring
DefaultPT1H
Formatduration
waitUntilRunningstring
DefaultPT10M
Formatduration
computeEnvironmentArn*Requiredstring
region*Requiredstring
type*Requiredobject
accessKeyIdstring
bucketstring
completionCheckIntervalstring
DefaultPT5S
Formatduration
deletebooleanstring
Defaulttrue
endpointOverridestring
executionRoleArnstring
jobQueueArnstring
resources
Default{ "request": { "memory": "2048", "cpu": "1" } }
request*Required
cpu*Requiredstring
memory*Requiredstring
resumebooleanstring
Defaulttrue
secretKeyIdstring
sessionTokenstring
sidecarResources
request*Required
cpu*Requiredstring
memory*Requiredstring
stsEndpointOverridestring
stsRoleArnstring
stsRoleExternalIdstring
stsRoleSessionDurationstring
DefaultPT15M
Formatduration
stsRoleSessionNamestring
syncWorkingDirectorybooleanstring
Defaultfalse
taskRoleArnstring
versionstring
waitUntilCompletionstring
DefaultPT1H
Formatduration
Default0
SubTypestring
Definitions