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:

id: api_python_sql
namespace: dev

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

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

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

  - id: sql_query
    type: io.kestra.plugin.jdbc.duckdb.Query
      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

  - type: io.kestra.plugin.scripts.python.Script
      runner: 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.