Trigger and Create Scenario using External API's

Options
sj0071992
sj0071992 Partner, Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Dataiku DSS Developer, Neuron 2022, Neuron 2023 Posts: 131 Neuron

Hi Team,

I just want to confirm like, can we trigger or Create a Dataiku Scenario using External Python rest API's?

Thanks in Advance

Answers

  • VitaliyD
    VitaliyD Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 102 Dataiker
    edited July 17
    Options

    Hi @sj0071992
    ,

    Yes, you can trigger the scenario programmatically using external Dataiku API. Please find the code sample below:

    import dataikuapi
    
    host = "DSS_host"
    global_api_key = "your_api_key"
    project_key = 'new_model'
    
    ​scenario_name = 'scenario_name'
    client = dataikuapi.DSSClient(host, global_api_key)
    project = client.get_project(project_key)
    scenario = project.get_scenario(scenario_name)
    
    ​scenario.run_and_wait()

    To create a scenario, you will need to use the Projects API create_scenario() function:
    https://doc.dataiku.com/dss/latest/python-api/projects.html#dataikuapi.dss.project.DSSProject.create_scenario

    For a complete list of available Scenario API functions, please refer to our documentation here:
    https://doc.dataiku.com/dss/latest/python-api/scenarios.html
    https://doc.dataiku.com/dss/latest/python-api/scenarios-inside.html

    Best,
    Vitaliy

  • Tanguy
    Tanguy Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron, Dataiku DSS Adv Designer, Registered, Dataiku DSS Developer, Neuron 2023 Posts: 112 Neuron
    Options

    Why does dataiku allow to create a scenario using dataiku's API but does not allow to modify the created scenario (I am trying to do this : create a scenario from a plugin and then define its content but dataiku only allows to modify a scenario inside it, not outside it)?

  • VitaliyD
    VitaliyD Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 102 Dataiker
    edited July 17
    Options

    Hi, you probably mean modifying the scenario's settings. You can do it by following examples from our docs https://doc.dataiku.com/dss/latest/python-api/scenarios.html#enable-scenarios-from-a-list-of-ids.

    For example, you can do something like below:

    import dataiku
    client = dataiku.api_client()
    project = client.get_default_project()
    scenario = project.get_scenario("scenario_id")
    settings = scenario.get_settings()
    raw_setttings = settings.get_raw()
    #modify raw settings:
    raw_setttings["name"] = "new_name"
    #and save the settings:
    settings.save()

    If the above is not what you mean, please elaborate on what you want to modify and provide an example.

  • Tanguy
    Tanguy Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron, Dataiku DSS Adv Designer, Registered, Dataiku DSS Developer, Neuron 2023 Posts: 112 Neuron
    Options

    Thanks for the reply @VitaliyD
    . I have tried to do that, however my objectif is to change the content of a scenario (e.g. adding and specifying a new step or changing python code inside a scenario). I have not managed to do this with a step-based scenario, but it seems it is possible to change the code of a custom code scenario.

  • lightnessofbein
    lightnessofbein Registered Posts: 5
    Options

    Hey @tanguy
    , have you found a way to change the code of a custom scenario? I only found a way to change the code of step with custom Python code in step-based scenarios, no clue how to do it for custom code scenarios.

  • Tanguy
    Tanguy Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron, Dataiku DSS Adv Designer, Registered, Dataiku DSS Developer, Neuron 2023 Posts: 112 Neuron
    Options

    Hi @lightnessofbein
    , I am interested in your solution to modify custom python code in a step based scenario .

    Regarding custom scenarios, maybe you can change it by using the payload methods (there is `get_payload` method and a `set_payload` method)?

    modify_scenarios.JPG

Setup Info
    Tags
      Help me…