Global variable

Dheerendra
Dheerendra Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Registered Posts: 21 ✭✭✭✭

Hi,

How can we create global variable in prepare recipe or scenarios ?

Thanks

Answers

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 Dataiker
    edited July 17

    Hi,

    By global variables,

    I assume you mean instance-level variables correct? These can be set using the dssclient.set_variables. This requires admin permissions.

    import dataiku
    from dataiku import pandasutils as pdu
    import pandas as pd
    
    client = dataiku.api_client()
    global_variables = client.get_variables()
    global_variables["today_year"] = "2021"
    client.set_variables(global_variables)
    
    #validate for testing only
    global_variables = client.get_variables()
    
    print(global_variables)

    For project global variables these need to be set with the following and global variables which are referred to as "standard" variables there are also local variables, which are not included in bundles.

    import dataiku
    from dataiku import pandasutils as pdu
    import pandas as pd
    
    client = dataiku.api_client()
    
    project = current_project = client.get_project(dataiku.default_project_key())
    project_variables = project.get_variables()
    #set global project variables 
    project_variables ['standard']['new_var_name'] = 'value'
    #set local project variables
    project_variables ['local']['new_var_name'] = 'value'
    project.set_variables(project_variables)
    
    
    #validate for testing only
    variables = project.get_variables()
    print(variables)
  • Dheerendra
    Dheerendra Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Registered Posts: 21 ✭✭✭✭

    Thanks Alex for response.

    Could you please help let me if we can create global variable at scenario (schedule the job) or at visual receipe level

    Thanks

    Dheerendra

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 Dataiker

    Yes, you can also add global variables, project and scenario variables via a scenario step. As seen below. Visual recipe would not set global variables but they can be used by visual recipes see :

    https://doc.dataiku.com/dss/latest/variables/index.html

    Screenshot 2021-07-29 at 11.42.37.png

  • Dheerendra
    Dheerendra Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Registered Posts: 21 ✭✭✭✭

    Many Thanks Alex!!!

Setup Info
    Tags
      Help me…