Community Conundrum 10: The Titanic is now live Learn more

Python: Getting global variables from inside and outside DSS

Level 2
Python: Getting global variables from inside and outside DSS

When I am running a script inside DSS, I can do this:

from dataiku.scenario import Scenario
s = Scenario()
vars = s.get_all_variables()
print(vars)

When I am using an external client, I can get variables like this:

import dataikuapi
client = dataikuapi.DSSClient("myhost", "mykey")
vars = client.get_variables()
priint(vars)

My questions are:

  • is there a more common way to achieve this whether inside or outside?
  • why do I need to be an admin user to run "client.get_variables()" when outside DSS when this isn't required in a recipe?
0 Kudos
2 Replies
Dataiker
Dataiker

Hi John,

 

You can use the dataiku internal python api to get access to project variables without starting a DSS client. 

Something like this should help you 

import dataiku

proj_var = dataiku.get_custom_variables()

0 Kudos
Level 2
Author

Hi Alex,

Thanks for the response.

My requirement is to access global and project variables. For testing with an external client I won't necessarily have a project context so my choice seems to be between "get_all_variables()" internally and "get_variables()" externally. For the latter, it seems I need admin privileges; this is not a problem long-term but it adds a bit of inconsistency in testing code developed on a PC.

John

0 Kudos