Community Conundrums are live! Learn more

global variable update

Level 1
global variable update

Hi,

I need to set an automatic update of some date variables (the update is going to be recursive; each month it is going to add a month), which then will be used in a SQL receipts flow.

At the moment my solution is to create a date variable (dictionary containing the desired dates) and a Python script (inside a Python Notebook) that perform the update of the element of the dictionary, giving as output a dictionary of updated dates (formatted as unicode and so which can be used in the SQL receipt). I will then run the script and the SQL flow in a scenario, running each month.

The only thing I am missing is how to save back the dictionary into a project variable, inside the Python script.

Does such a function exist? Am I using a correct strategy?

Thank you very much for your help.

Regards,

 

Alessandro

0 Kudos
2 Replies
Dataiker
Dataiker

Hi,

Assuming that you want to update the variable "stuff" in your project, use the following code:

import dataiku

client = dataiku.api_client()
project = client.get_project("MYPROJECT")

variables = project.get_variables()
variables["standard"]["stuff"] = "my new value for stuff variable"
project.set_variables(variables)
Level 1
Author

Thank you very much; it worked and I got the update I was looking for.

 

Kind regards,

Alessandro

0 Kudos