Script icon

Run a Python script and generate outputs, metrics and files specified with a variable

Run a parametrized Python script in Kestra that produces a downloadable CSV, named outputs, and custom counters and timers. Drive behavior with workflow variables.

Categories
CoreData

Run a Python script as an orchestrated task that produces real, observable results: a downloadable file, structured outputs, and custom metrics. This blueprint generates a CSV of 100 synthetic orders, computes the total and average order value, and surfaces those numbers as Kestra outputs and metrics so downstream tasks, dashboards, and stakeholders can consume them. It solves a common gap with ad hoc Python: scripts that write files and print numbers locally but leave nothing tracked, versioned, or shareable.

How it works

  • The analyze_orders task runs io.kestra.plugin.scripts.python.Script with its dependencies set to faker and kestra, installed automatically at runtime.
  • The script reads the {{ vars.file }} variable (default orders.csv) to decide the output filename, avoiding hardcoded paths.
  • It builds 100 fake orders with Faker, writes them to the CSV, then computes total_sum and average_order.
  • outputFiles is set to *.csv, so Kestra captures the generated file into internal storage for download.
  • The script calls Kestra.outputs(...) for total_sum and average_order, Kestra.counter(...) for both values, and Kestra.timer(...) for processing_time, all tagged with the filename.

What you get

  • A CSV artifact downloadable from the Execution page in the UI.
  • Named outputs (total_sum, average_order) usable by later tasks via expressions.
  • Custom counters and a timer visible in the Kestra metrics view.
  • A fully parametrized run controlled by a single variable.

Who it's for

  • Data engineers wrapping existing Python in a tracked, schedulable pipeline.
  • Analysts who need shareable file outputs without manual exports.
  • Platform teams standardizing how scripts emit metrics and artifacts.

Why orchestrate this with Kestra

Python's own runtime has no scheduler, no retry policy, and no built-in way to track outputs or metrics across runs. Kestra adds event and schedule triggers, automatic retries, execution lineage, and declarative YAML so the same script becomes reproducible and observable. Outputs and outputFiles are captured centrally instead of vanishing on the worker, and metrics are queryable over time.

Prerequisites

  • A running Kestra instance.
  • Python available in the execution environment (the task installs faker and kestra).

Secrets

  • None. This blueprint references no secret(...) values.

Quick start

  1. Add the flow to your Kestra instance.
  2. Execute it as is to generate orders.csv.
  3. Open the Execution page to download the file and inspect outputs.
  4. Check the metrics tab for the counters and timer.

How to extend

  • Override the file variable to change the output name per execution.
  • Add a schedule or event trigger to run it automatically.
  • Replace the synthetic data logic with a real extract from your source.
  • Pass total_sum into a downstream notification or database task.

Links

Tasks
Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.