Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
I have a python recipe in my scenario working with a local variable.
I have succesfully executed my scenario within the webapp but :
How can I change the local variable from the webapp's code (in the Python back-end) ?
Hi @Redouxne,
Are you using a scenario variable or a project variable? Indeed, for scenario variables, it's only possible to set them from within the context of a scenario.
So, if you want to set a variable that will be used in a scenario but set it from a Webapp, you'll probably want to use a project variable instead. You can see the following code example for how to set a variable from the Python API, which can be run in the Python backend.
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
variables = project.get_variables()
variables['standard']['some_variable'] = 'some_value'
project.set_variables(variables)
Then, from your scenario you can obtain this variable in a Python step:
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
variables = project.get_variables()
some_variable_value = variables['standard']['some_variable']
Let me know if this approach doesn't work for you!
Thank you,
Sarina
Hi @Redouxne,
Are you using a scenario variable or a project variable? Indeed, for scenario variables, it's only possible to set them from within the context of a scenario.
So, if you want to set a variable that will be used in a scenario but set it from a Webapp, you'll probably want to use a project variable instead. You can see the following code example for how to set a variable from the Python API, which can be run in the Python backend.
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
variables = project.get_variables()
variables['standard']['some_variable'] = 'some_value'
project.set_variables(variables)
Then, from your scenario you can obtain this variable in a Python step:
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
variables = project.get_variables()
some_variable_value = variables['standard']['some_variable']
Let me know if this approach doesn't work for you!
Thank you,
Sarina
Hi Sarina,
Thank you ! At first glance it seems to work, I have another question, do you know how to know when the scenario ended and get the information in my Python back-end ?
Thank you again,
Redouane
Please raise a new thread as this is a different question and this thread has been marked as resolved already.