Blueprints

Add a parametrized Python script as a Namespace File and run it in parallel in Docker containers

About this blueprint

Docker Namespace Files Python

Add a Python script called parametrized.py as a Namespace File and run it in parallel with different parameter values using a Python script added as a Namespace File.

Here is the content of the parametrized.py script:

python
import argparse

parser = argparse.ArgumentParser()

parser.add_argument("--num", type=int, default=42, help="Enter an integer")

args = parser.parse_args()
result = args.num * 2
print(result)

You can add that file directly from the embedded Visual Studio Code Editor in the Kestra UI.

yaml
id: parallel_python
namespace: company.team

tasks:
  - id: parallel
    type: io.kestra.plugin.core.flow.EachParallel
    value: [1, 2, 3, 4, 5, 6, 7, 8, 9]
    tasks:
      - id: python
        type: io.kestra.plugin.scripts.python.Commands
        namespaceFiles: 
          enabled: true
        taskRunner:
          type: io.kestra.plugin.scripts.runner.docker.Docker
        containerImage: ghcr.io/kestra-io/pydata:latest
        commands:
          - python parametrized.py --num {{ taskrun.value }}

Each Parallel

Commands

New to Kestra?

Use blueprints to kickstart your first workflows.

Get started with Kestra