Reference | Coding with variables#

Although you do not need to be a coder to take advantage of variables, code provides the flexibility to take variables even further. For that purpose, coders will want to explore the Variables for Coders course in the Developer learning path. However, we can take a brief look here at how coders can work with variables.

Defining variables#

All variables are defined as a JSON object. When naming variables, you should follow a convention that uses a descriptive noun and includes only alphanumeric characters or the underscore character.

You can manually define project variables by selecting … > Variables from the top navigation bar in Dataiku, and typing the applicable JSON code.

A Dataiku screenshot of the project variables page with two global variables defined as an example.

To let others know how the project variables are defined, you can document them in the project’s wiki.


The project variables page has a section for global variables and local variables. While the variables that are defined in both sections are project-specific, those that are defined in the “local variables” section are also instance-specific. Therefore, local variables are not exported when you bundle a project for the purpose of deploying it from the Design node to the Automation node.

You can also visit the reference documentation for more details.

Using variables in a code recipe#

You can define and call variables from any place where you can write code within Dataiku, such as notebooks or code recipes.

The syntax used to define and call variables depends on the code language used in a recipe. For example, the following code in an SQL Recipe calls a variable “your_variable_name”:

WHERE "column" = '${your_variable_name}'

The Dataiku Python API offers multiple ways of getting and setting variables. For example, the following code in a Python recipe calls a variable “your_variable_name”:

import dataiku

Instead of get_custom_variables(), you can also define a Python dictionary of variables after creating a project handle:

import dataiku
p = dataiku.Project() # create a project handle
variables = p.get_variables() # retrieve your variables as a dictionary
variables["standard"]["your_variable_name"] = "your_variable_value" # manipulate the dictionary to update the variable you want
p.set_variables(variables) # set the updated dictionary


get_variables gets the variables of this project. Visit the Developer Guide for the API reference.

As you can see, when calling and updating a variable via code, such as in a code recipe, the core objective is the same as when calling a variable using a visual recipe.

Using code, you can leverage your variables in coding recipes and webapps. You can leverage scenarios to automate the variable update process. For example, you can combine scenarios with applications to update the project variables based on user input, or external parameters such as dates.