Working with Project variables

nitinrsharma
Level 1
Working with Project variables

Hi ,

 

We are working  with access global variables and using that to do some operation and want to write it back to local variables of the project but keep the global variable untouched. set_variables do not have option to differentiate between global and local and thus creating an issue by overwriting both and messing up the json structure, same for update variables. Do we have a elegant solution to this ?

0 Kudos
1 Reply
AlexT
Dataiker

Hi,

You should be able to set global project variables ( standard)  and local project variables.

Please see the below sample :

import dataiku
project = dataiku.api_client().get_project(dataiku.default_project_key())

vars = project.get_variables()
#set global variables
vars['standard']['variable_name'] = "global_variable"
#set local variables 
vars['local']['variable_name'] = "local_variables"
project.set_variables(vars)

 

Thanks