How to store or print all project recipes as string using python

JV
JV Registered Posts: 1 ✭✭✭

Dear sir/Madam,

I need to build a python script that retrieves for every recipe (SQL) in a given project (project name = 'RANDOM') its content as a string.

I will put the output (recipe as a string) in a dictionary, with the recipe name as a key.

Do you have any Dataiku specific functions that gets the recipe query, or do you have ideas to be able to iterate over all recipes and store the recipe content?

Thanks for the support!


Operating system used: Windows

Tagged:

Answers

  • Marlan
    Marlan Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Dataiku Frontrunner Awards 2021 Participant, Neuron 2023 Posts: 319 Neuron
    edited July 17

    Hi @JV
    ,

    The following code should get you started:

    import dataiku
    client = dataiku.api_client()
    
    project_obj = client.get_project('SOMEPROJKEY')
    recipe_types = ('sql_script', 'sql_query')
    
    for recipe_specs in project_obj.list_recipes():
        if recipe_specs['type'] in recipe_types:
            recipe_obj = project_obj.get_recipe(recipe_specs['name'])
            recipe_settings_obj = recipe_obj.get_settings()
            recipe_payload = recipe_settings_obj.str_payload
            
            print(recipe_specs['name'])
            print(recipe_payload)

    Note that I extracted the following code snippet from a search and replace process and haven't run it after doing that so possible that there are some typos or something.

    Also, this will only work for projects you have access to. To access other projects you'd need to get the client using an API key .

    Marlan

Setup Info
    Tags
      Help me…