Variable expansion

Options
tomas
tomas Registered, Neuron 2022 Posts: 120 ✭✭✭✭✭
edited July 16 in Using Dataiku

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

Tagged:

Best Answer

  • Marlan
    Marlan Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Dataiku Frontrunner Awards 2021 Participant, Neuron 2023 Posts: 317 Neuron
    edited July 17 Answer ✓
    Options

    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

Setup Info
    Tags
      Help me…