Access Project Variable from a different project

ifotopoulos
ifotopoulos Registered Posts: 9 ✭✭✭✭
Is it possible to access a project variable from a different project?

As an example I have a project A, that creates a project variable A.CURRENT_PERIOD , ideally I would like to access this variable from different projects.

I tried to use global variables but when I'm trying to update them I'm getting the following error

"You may not update global variables"

Thanks
Tagged:

Answers

  • Alex_Combessie
    Alex_Combessie Alpha Tester, Dataiker Alumni Posts: 539 ✭✭✭✭✭✭✭✭✭
    edited July 18

    Hi,

    For updating global variables, you need to use Dataiku Public API. See example below:


    import dataiku
    client = dataiku.api_client()

    global_variables = client.get_variables()
    print(global_variables)

    global_variables["foo"] = "bar"
    client.set_variables(global_variables)
    print(global_variables)

    The full documentation is located here for your reference: https://doc.dataiku.com/dss/latest/python-api/rest-api-client/client.html#dataikuapi.dssclient.DSSClient.get_variables

    [EDIT] The answer above only works if your user has an ADMIN role on Dataiku. Otherwise, you can use the following code to edit the variable of one project from another:


    import dataiku
    client = dataiku.api_client()

    project = client.get_project("TSFORECAST")
    my_other_project_variables = project.get_variables()
    print(my_other_project_variables)

    my_other_project_variables["standard"]["foo"] = "bar"
    project.set_variables(my_other_project_variables)
    print(my_other_project_variables)

    Hope it helps,

    Alex

  • ifotopoulos
    ifotopoulos Registered Posts: 9 ✭✭✭✭
    Hi Alex,

    Thanks a lot for your help and your quick reply :)
    I tried to run this code but unfortunately I'm getting an error that only Admins are allowed to update global variables. Getting admin access it's most likely out of question since I'm a user in a multi-tenant environment.

    Is there any other workaround ?
  • Alex_Combessie
    Alex_Combessie Alpha Tester, Dataiker Alumni Posts: 539 ✭✭✭✭✭✭✭✭✭
    Hi,
    Indeed editing global variables are an admin-only feature, since they are shared by all projects. In a multi-tenant environment, this must be managed by admins to ensure one user would not accidentally cause another user code to stop running.
    The workaround would be to use the Dataiku public API to access the variables of the other project. I will add another code snippet for this.
Setup Info
    Tags
      Help me…