Discover this year's submissions to the Dataiku Frontrunner Awards and give kudos to your favorite use cases and success stories!READ MORE

DSSRecipeDefinitionAndPayload set recipe output

Solved!
tomas
Neuron
Neuron
DSSRecipeDefinitionAndPayload set recipe output

Hi,



 I would like to add a new folder to the recipe's output, bases on the documentaion there is just a get method for recipe inputs/outputs.



Is there any way to set it?



Thanks



classdataikuapi.dss.recipe.DSSRecipeDefinitionAndPayload(data)



Definition for a recipe, that is, the recipe definition itself and its payload



get_recipe_raw_definition()



get_recipe_inputs()



get_recipe_outputs()



get_recipe_params()



get_payload()



get_json_payload()



set_payload(payload)



set_json_payload(payload)

0 Kudos
1 Solution
Alex_Combessie
Dataiker Alumni

Hi,



You can use the set_definition_and_payload method of the class dataikuapi.dss.recipe.DSSRecipe to update an existing recipe. This is highlighted in https://doc.dataiku.com/dss/latest/api/public/client-python/reference.html#dataikuapi.dss.recipe.DSSRecipe.set_definition_and_payload.



Otherwise, if you want to create a new recipe, you will need a dataikuapi.dss.recipe.DSSRecipeCreator class (see https://doc.dataiku.com/dss/latest/api/public/client-python/reference.html#dataikuapi.dss.recipe.DSSRecipeCreator)



Cheers,



Alex

View solution in original post

0 Kudos
5 Replies
Alex_Combessie
Dataiker Alumni

Hi,



You can use the set_definition_and_payload method of the class dataikuapi.dss.recipe.DSSRecipe to update an existing recipe. This is highlighted in https://doc.dataiku.com/dss/latest/api/public/client-python/reference.html#dataikuapi.dss.recipe.DSSRecipe.set_definition_and_payload.



Otherwise, if you want to create a new recipe, you will need a dataikuapi.dss.recipe.DSSRecipeCreator class (see https://doc.dataiku.com/dss/latest/api/public/client-python/reference.html#dataikuapi.dss.recipe.DSSRecipeCreator)



Cheers,



Alex

0 Kudos
tomas
Neuron
Neuron
Author
Yes I know, but can you give me an example? I dont know how to change inside the definition object the inputs/outputs.

folder = prj.get_managed_folder('qFs1aIyX')
recipe=dataikuapi.dss.recipe.DSSRecipe(client, 'S3_IMPORT', 'compute_process_s3')
df=recipe.get_definition_and_payload()
##########################################
# Here I want to add the folder as a recipe output:
df.add_recipe_input?( folder )
##########################################

recipe.set_definition_and_payload(df)

Thanks!
0 Kudos
Alex_Combessie
Dataiker Alumni
Hi,
You need to get the result of get_definition_and_payload() and modify it. It is a Python dictionary which contains all elements describing the recipe and its outputs. Then once modified, pass it back to set_definition_and_payload().
Cheers,
Alex
0 Kudos
tomas
Neuron
Neuron
Author
Hi Tomas,
Sorry about this, I forgot one step: you need to modify the result of get_recipe_raw_definition() on the DSSRecipeDefinitionAndPayload instance in order to then use set_definition_and_payload(). So if I put it all back together, you will need:

import dataiku
import dataikuapi
client = dataiku.api_client()
project = client.get_project(dataiku.default_project_key())
recipe = dataikuapi.dss.recipe.DSSRecipe(client, 'SANDBOX', 'compute_something')
definition_and_payload = recipe.get_definition_and_payload()
print(definition_and_payload.get_recipe_raw_definition())
# Here you modify the raw definition in-place as a Python dictionary (example below)
definition_and_payload.get_recipe_raw_definition()["outputs"] = {u'main': {u'items': [{u'appendMode': False,
u'ref': u'JZLLhzOn'}]}}
recipe.set_definition_and_payload(definition_and_payload)
# Now you will get a message telling you that the recipe has been updated. You can verify with:
print(recipe.get_definition_and_payload().get_recipe_raw_definition())
0 Kudos
tomas
Neuron
Neuron
Author
Thanks, that worked!
0 Kudos

Labels

?
Labels (4)
A banner prompting to get Dataiku