Submit your innovative use case or inspiring success story to the 2023 Dataiku Frontrunner Awards! LET'S GO

Change SQL recipe code with dataikuapi

Solved!
imanousar
Level 3
Change SQL recipe code with dataikuapi

I want to perform changes in the code of my SQL recipes in a project. How can I access the code?

 

 

import dataiku
import dataikuapi

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

recipes = project.list_recipes()

for recipe in recipes:
    recipe_code = recipe.get_code()   # can't figure out this step
    alter_code(recipe_code)​

 

0 Kudos
1 Solution
AlexT
Dataiker

Hi @imanousar,

For SQL recipe  you need to use get_payload() and set_payload() instead of get_code(), which only works for R/Python/Bash recipes and not SQL.

client = dataiku.api_client()
current_project = client.get_project(dataiku.default_project_key())
current_recipe = current_project.get_recipe("compute_outnow")
recipe_settings = current_recipe.get_settings()
code = recipe_settings.get_payload()
final_code = 'SELECT abc,edf FROM "TESTING_2_postgres_out"'
recipe_settings.set_payload(final_code)
recipe_settings.save()

View solution in original post

0 Kudos
1 Reply
AlexT
Dataiker

Hi @imanousar,

For SQL recipe  you need to use get_payload() and set_payload() instead of get_code(), which only works for R/Python/Bash recipes and not SQL.

client = dataiku.api_client()
current_project = client.get_project(dataiku.default_project_key())
current_recipe = current_project.get_recipe("compute_outnow")
recipe_settings = current_recipe.get_settings()
code = recipe_settings.get_payload()
final_code = 'SELECT abc,edf FROM "TESTING_2_postgres_out"'
recipe_settings.set_payload(final_code)
recipe_settings.save()
0 Kudos