Task defaults is a list of default values applied to each task of a certain type within your flow(s). Task defaults are like default function's arguments — they help avoid repetition when a given task or plugin is often called with the same values.

You can add task defaults to avoid repeating task properties on multiple occurrences of the same task in a taskDefaults properties. For example:

yaml
id: api_python_sql
namespace: dev

tasks:
  - id: api
    type: io.kestra.plugin.fs.http.Request
    uri: https://dummyjson.com/products

  - id: hello
    type: io.kestra.plugin.scripts.python.Script
    docker:
      image: python:slim
    script: |
      print("Hello World!")

  - id: python
    type: io.kestra.plugin.scripts.python.Script
    docker:
      image: python:slim
    beforeCommands:
      - pip install polars
    warningOnStdErr: false
    script: |
      import polars as pl
      data = {{outputs.api.body | jq('.products') | first}}
      df = pl.from_dicts(data)
      df.glimpse()
      df.select(["brand", "price"]).write_csv("{{outputDir}}/products.csv")

  - id: sql_query
    type: io.kestra.plugin.jdbc.duckdb.Query
    inputFiles:
      in.csv: "{{ outputs.python.outputFiles['products.csv'] }}"
    sql: |
      SELECT brand, round(avg(price), 2) as avg_price
      FROM read_csv_auto('{{workingDir}}/in.csv', header=True)
      GROUP BY brand
      ORDER BY avg_price DESC;
    store: true

taskDefaults:
  - type: io.kestra.plugin.scripts.python.Script
    values:
      runner: DOCKER
      docker:
        image: python:slim
        pullPolicy: ALWAYS # set it to NEVER to use a local image

Here, we avoid repeating Docker and Python configurations in each task by directly setting those within the taskDefaults property. This approach helps to streamline the configuration process and reduce the chances of errors caused by inconsistent settings across different tasks.

Note that when you move some required task attributes into the taskDefaults property, the code editor within the UI will complain that the required task argument is missing. The editor shows this message because taskDefaults are resolved at runtime and the editor is not aware of those default attributes until you run your flow. As long as taskDefaults contains the relevant arguments, you can save the flow and ignore the warning displayed in the editor.

taskDefaultsWarning