Skip to content
Components Updated November 20, 2026

Variables Tutorial

Use variables through the API in two parts: run a Generic Extractor with values in the job, then a Python transformation with default, stored and inline values.

This tutorial will guide you through basic usage of Variables in the component configuration, in two parts. In part 1, the result is a parametrized configuration of the Generic Extractor, run with values passed in the job. In part 2, it is a parametrized Python transformation with stored default values, run three times with default, stored and inline values. This approach can be applied to any component.

In the examples, we use the curl console tool to interact with our APIs.

Part 1: a Generic Extractor with values in the job

Section titled “Part 1: a Generic Extractor with values in the job”

First, store the API endpoints as environment variables, so we don’t have to repeat ourselves.

We will need:

  • Storage API to store the variable definitions and the extractor configuration.
  • Jobs API to run the extractor job from the configuration.

The host names depend on your stack:

Terminal window
export STORAGE_API_HOST="https://connection.keboola.com"
export JOB_QUEUE_HOST="https://queue.keboola.com"

A Storage API Token is needed to interact with the Keboola APIs.

Obtain a Storage API token from the user interface of your project, see this Guide. The token must be allowed to manage component configurations — a read-only token fails at the create-configuration step.

Then store the token to the environment variable.

Terminal window
export TOKEN="..."

The next step is to define the variables in a Variable Configuration.

Define name and type of the variables.

Terminal window
export VARIABLE_CONFIG_NAME="Extractor variables"
export VARIABLE_CONFIG='
{
"variables": [
{
"name": "outputBucket",
"type": "string"
},
{
"name": "id",
"type": "int"
}
]
}
'

Use Create Configuration API call (opens in a new tab) to store variable configuration.

Terminal window
curl --include \
--request POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "X-StorageApi-Token: $TOKEN" \
--data-urlencode "name=$VARIABLE_CONFIG_NAME" \
--data-urlencode "configuration=$VARIABLE_CONFIG" \
"$STORAGE_API_HOST/v2/storage/components/keboola.variables/configs"

Example API call result.

{
"id":"1234",
"name":"Extractor variables",
"description":"..."
}

Save variable configuration id from the result to the environment variable.

Terminal window
export VARIABLE_CONFIG_ID="1234"

The created variable configuration defines the names and types of variables.

Default values live in configuration rows of this same variable configuration, referenced from the main configuration by variables_values_id — see Variable Values.

In this example, the values of the variables are entered directly to the run API call (see below), so configuration with the variable values is not used.

Define extractor configuration with variables {{placeholders}}.

Terminal window
export COMPONENT_ID="ex-generic-v2"
export EXTRACTOR_CONFIG_NAME="Extractor configuration"
export EXTRACTOR_CONFIG='
{
"parameters": {
"api": {
"baseUrl": "https://jsonplaceholder.typicode.com/"
},
"config": {
"debug": true,
"outputBucket": "{{outputBucket}}",
"jobs": [
{
"endpoint": "posts/{{id}}/comments"
}
]
}
},
"variables_id": "'$VARIABLE_CONFIG_ID'"
}
'

Use Create Configuration API call (opens in a new tab) to store extractor configuration.

Terminal window
curl --include \
--request POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "X-StorageApi-Token: $TOKEN" \
--data-urlencode "name=$EXTRACTOR_CONFIG_NAME" \
--data-urlencode "configuration=$EXTRACTOR_CONFIG" \
"$STORAGE_API_HOST/v2/storage/components/$COMPONENT_ID/configs"

Example API call result.

{
"id":"4567",
"name":"Extractor configuration",
"description":"..."
}

Save extractor configuration id from the result to the environment variable.

Terminal window
export EXTRACTOR_CONFIG_ID="4567"

Define values of the variables. Both values are quoted — the API declares a variable value as a string.

Terminal window
export VARIABLES_VALUES='
[
{"name": "outputBucket", "value": "my-bucket"},
{"name": "id", "value": "1"}
]
'

In this example the values of the variables are part of the run job request.

For other ways to define values see the Variables documentation.

Use Run Job API call (opens in a new tab) to run extractor configuration. The body is passed on standard input, so the multi-line $VARIABLES_VALUES survives intact — inlining it as '$VARIABLES_VALUES' makes bash split it on whitespace and truncates the request.

Terminal window
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "X-StorageApi-Token: $TOKEN" \
--data-binary @- \
"$JOB_QUEUE_HOST/jobs" <<EOF
{
"component": "$COMPONENT_ID",
"config": "$EXTRACTOR_CONFIG_ID",
"mode": "run",
"variableValuesData": {
"values": $VARIABLES_VALUES
}
}
EOF

The run-job call returns a job object that includes its id and status. Save the job id from the result to the environment variable:

Terminal window
export JOB_ID="..."

Poll the job by its ID to follow progress:

Terminal window
curl --header "X-StorageApi-Token: $TOKEN" \
"$JOB_QUEUE_HOST/jobs/$JOB_ID"

The status progresses from processing to success when the job finishes (or error on failure, with details in the result field).

In the Keboola UI you can see the same job — in the picture below, the entered values of the variables were used.

Screenshot -- Job

A note about the replaced variables is in the job logs.

Screenshot -- Job Logs

See the Variables documentation for more information.

Part 2: stored default values and run-time overrides

Section titled “Part 2: stored default values and run-time overrides”

In this example, we will configure a Python transformation using variables.

Part 2 reuses the calls from part 1, Create Configuration and Run Job, with different variables (alias and size) and a Python transformation in place of the Generic Extractor. It adds what part 1 leaves out: default values stored in a configuration row, and three successive runs that take the values from different places.

Use the Create Configuration API call (opens in a new tab) for the keboola.variables component with the following content:

{
"variables": [
{
"name": "alias",
"type": "string"
},
{
"name": "size",
"type": "string"
}
]
}

See an example (opens in a new tab).

Step 2: create default values for the variables

Section titled “Step 2: create default values for the variables”

Note that this step is optional — you can use variables without default values. In the previous step, you obtained an ID of the variable configuration. Use the Create Configuration Row API call (opens in a new tab). Use the ID of the variable configuration and keboola.variables as a component. Use the following body:

{
"values": [
{
"name": "alias",
"value": "batman"
},
{
"name": "size",
"value": "42"
}
]
}

See an example (opens in a new tab)

Now it is time to create the actual configuration which will contain a Python transformation. Use the Create Configuration API call (opens in a new tab) for the keboola.python-transformation-v2 component with the following configuration body. The storage section describes the standard input and output mapping.

{
"storage": {
"input": {
"tables": [
{
"source": "in.c-variable-testing.{{alias}}",
"destination": "{{alias}}.csv"
}
]
},
"output": {
"tables": [
{
"source": "new-table.csv",
"destination": "out.c-variable-testing.cars"
}
]
}
},
"parameters": {
"blocks": [
{
"name": "First Block",
"codes": [
{
"name": "First Code",
"script": [
"import csv\ncsvlt = '\\n'\ncsvdel = ','\ncsvquo = '\"'\nwith open('in/tables/{{alias}}.csv', mode='rt', encoding='utf-8') as in_file, open('out/tables/new-table.csv', mode='wt', encoding='utf-8') as out_file:\n writer = csv.DictWriter(out_file, fieldnames=['COUNTRY', 'CARS'], lineterminator=csvlt, delimiter=csvdel, quotechar=csvquo)\n writer.writeheader()\n\n lazy_lines = (line.replace('\\0', '') for line in in_file)\n reader = csv.DictReader(lazy_lines, lineterminator=csvlt, delimiter=csvdel, quotechar=csvquo)\n for row in reader:\n writer.writerow({'COUNTRY': row['COUNTRY'] + '{{ alias }}', 'CARS': row['CARS'] + '{{ size }}'})\nfrom pathlib import Path\nimport sys\ncontents = Path('/data/config.json').read_text()\nprint(contents, file=sys.stdout)"
]
}
]
}
]
},
"variables_id": "807968875",
"variables_values_id": "807952812"
}

The variables_id property contains the ID of the variable configuration - e.g., 807968875. The variables_values_id property is optional and contains the ID of the row with default values - e.g., 807952812.

The IDs in part 2 (807968875, 807952812, 807943784, 807957572) are examples from one project, and other pages use different ones. Put in the IDs that your own calls return: the variable configuration from Step 1, the values row from Step 2, the main configuration from Step 3 and the second values row from Run 2.

The parameters section contains a script with the following Python code:

import csv
csvlt = '\n'
csvdel = ','
csvquo = '"'
with open('in/tables/{{alias}}.csv', mode='rt', encoding='utf-8') as in_file, open('out/tables/new-table.csv', mode='wt', encoding='utf-8') as out_file:
writer = csv.DictWriter(out_file, fieldnames=['COUNTRY', 'CARS'], lineterminator=csvlt, delimiter=csvdel, quotechar=csvquo)
writer.writeheader()
lazy_lines = (line.replace('\0', '') for line in in_file)
reader = csv.DictReader(lazy_lines, lineterminator=csvlt, delimiter=csvdel, quotechar=csvquo)
for row in reader:
writer.writerow({'COUNTRY': row['COUNTRY'] + '{{ alias }}', 'CARS': row['CARS'] + '{{ size }}'})
from pathlib import Path
import sys
contents = Path('/data/config.json').read_text()
print(contents, file=sys.stdout)

The script reads a file given by the alias, modifies the two columns COUNTRY and CARS, and prints the contents of the configuration file to output.

See an example (opens in a new tab).

You now run the transformation three times. Each run takes the variable values from a different place: the default values from Step 2, a second stored row of values, and values written into the job request. Which values a job needs, and which combinations raise an error, is in Variable values and Rules for providing values.

Before the first run, you have to create the source table. Unless you modified the mapping in the example, you have to create a bucket named variable-testing in the in stage. Then create a table called batman with columns COUNTRY and CARS. You can use this sample CSV file.

If you created the default values, you can now directly run the job. Use the Create Job API call (opens in a new tab) with the following body:

{
"component": "keboola.python-transformation-v2",
"config": "807943784",
"mode": "run"
}

The config property contains the ID of the main configuration. After you create the input table, you can run the job. See an example (opens in a new tab). It will create a new table in Storage — out.c-variable-testing.cars. The tables should contain the default values, e.g.:

COUNTRYCARS
Belgiumbatman629378142
Finlandbatman335823242
Italybatman4139387742
Romaniabatman654126042

The events of the job will contain the contents of the configuration file where you can verify that the variables were replaced.

Click to expand the configuration. ```json { "storage": { "input": { "tables": [ { "source": "in.c-variable-testing.batman", "destination": "batman.csv", "columns": [], "where_values": [], "where_operator": "eq" } ], "files": [] }, "output": { "tables": [ { "source": "new-table.csv", "destination": "out.c-variable-testing.cars", "incremental": false, "primary_key": [], "columns": [], "delete_where_values": [], "delete_where_operator": "eq", "delimiter": ",", "enclosure": "\"", "metadata": [], "column_metadata": [] } ], "files": [] } }, "parameters": { "blocks": [ { "name": "First Block", "codes": [ { "name": "First Code", "script": [ "import csv\ncsvlt = '\\n'\ncsvdel = ','\ncsvquo = '\"'\nwith open('in/tables/{{alias}}.csv', mode='rt', encoding='utf-8') as in_file, open('out/tables/new-table.csv', mode='wt', encoding='utf-8') as out_file:\n writer = csv.DictWriter(out_file, fieldnames=['COUNTRY', 'CARS'], lineterminator=csvlt, delimiter=csvdel, quotechar=csvquo)\n writer.writeheader()\n\n lazy_lines = (line.replace('\\0', '') for line in in_file)\n reader = csv.DictReader(lazy_lines, lineterminator=csvlt, delimiter=csvdel, quotechar=csvquo)\n for row in reader:\n writer.writerow({'COUNTRY': row['COUNTRY'] + '{{ alias }}', 'CARS': row['CARS'] + '{{ size }}'})\nfrom pathlib import Path\nimport sys\ncontents = Path('/data/config.json').read_text()\nprint(contents, file=sys.stdout)" ] } ] } ] }, "variables_id": "807968875", "variables_values_id": "807952812", "image_parameters": {}, "action": "run", "authorization": {} } ```

Similarly to the default values, you can store another set of values. Let’s add another configuration row to the existing variable configuration:

{
"values": [
{
"name": "alias",
"value": "WATMAN"
},
{
"name": "size",
"value": "4200"
}
]
}

See an example (opens in a new tab). You will obtain an ID of the row. Then create a table called WATMAN with columns COUNTRY and CARS. You can use this sample CSV file.

Run a job with parameters and provide the ID of the main configuration in the config property and the ID of the value row in variableValuesId:

{
"component": "keboola.python-transformation-v2",
"config": "807943784",
"mode": "run",
"variableValuesId": "807957572"
}

See an example (opens in a new tab). The output table now contains:

COUNTRYCARS
BelgiumWATMAN62937814200
FinlandWATMAN33582324200
ItalyWATMAN413938774200

The last run provides the values for variables directly in the job request. Variable values are entered in the variableValuesData property:

{
"component": "keboola.python-transformation-v2",
"config": "807943784",
"mode": "run",
"variableValuesData": {
"values": [
{
"name": "alias",
"value": "batman"
},
{
"name": "size",
"value": "scatman"
}
]
}
}

See an example (opens in a new tab).

The output table will contain:

COUNTRYCARS
Belgiumbatman6293781scatman
Finlandbatman3358232scatman
Italybatman41393877scatman

Next: Development branches →

Ask Kai

Hi, I'm Kai — Keboola's AI assistant for the docs. Ask me anything and I'll answer from the documentation and cite the pages I use.

Kai is an AI and can make mistakes. Check the sources it links.