Discover all of the brand-new features and improvements to existing capabilities in the Dataiku 11.3 updateLET'S GO

Variable expansion

Solved!
tomas
Variable expansion

Hi,

 I was wondering if there is an api in Dataiku Python API to replace all the template literals in strings. DSS uses in many places a javascript like template literals, for example, in dataset you can define a path as:

 

 

/exports/${environment}/${projectKey}/customers

 

 

When I do not know what placeholders are used it is pretty complicated to parse out all the placeholders and then fetch those values from variables (assuming that get_custom_variables handles prioritization of local/standard/global vars)

It would be super useful to have something like:

 

client = dataiku.api_client()
client.evaluate_vars(dataset_path)

 

 and it would replace all the known variables plus all the internal variables of DSS.

Thanks

 

0 Kudos
1 Solution
Marlan

Hi @tomas,

Definitely agree that it would be really nice to have a built-in method like you describe available in the API. 

A less convenient but workable approach is to use the Python Template class. It turns out that the Template class handles the ${varname} format. Here is an example:

import dataiku
from string import Template
t = '/exports/${environment}/${projectKey}/customers'
e = Template(t).substitute(dataiku.get_custom_variables())

 

Marlan

View solution in original post

0 Kudos
1 Reply
Marlan

Hi @tomas,

Definitely agree that it would be really nice to have a built-in method like you describe available in the API. 

A less convenient but workable approach is to use the Python Template class. It turns out that the Template class handles the ${varname} format. Here is an example:

import dataiku
from string import Template
t = '/exports/${environment}/${projectKey}/customers'
e = Template(t).substitute(dataiku.get_custom_variables())

 

Marlan

0 Kudos