Create Bundle which includes contents with Python API
MYassine
Dataiku DSS Core Designer, Registered Posts: 4 ✭✭✭
Hi,
I want to create a bundle with Dataiku API and include a dataset, a saved models , a managed folder and webapp.
Is it possible to include these contents with Dataiku API ?
Thank you in advance for your help,
Yassine
Tagged:
Best Answer
-
Sergey Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 365 Dataiker
Hi @MYassine
Here is the sample that you can use:
import dataiku client = dataiku.api_client() proj_key = "<project_key>" # Need to have a pre-created project variable called "version" assigned to a number as a count for the bundles proj = client.get_project(proj_key) proj_vars = proj.get_variables() current_vers = proj_vars['standard']['version'] # Running raw['bundleExporterSettings'] = {} # and saving the settings, there is no need for a dummy bundle. settings = proj.get_settings() raw = settings.get_raw() raw['bundleExporterSettings'] = {} settings.save() # Retrieve and update export options settings = proj.get_settings() export_options = settings.get_raw()['bundleExporterSettings']['exportOptions'] export_options['exportUploads'] = "True" export_options['exportSavedModels'] = "True" export_options['exportManagedFolders'] = "True" export_options['includedDatasetsData'].append({"name": "<dataset_1>"}) export_options['includedDatasetsData'].append({"name": "<dataset_2>"}) export_options['includedManagedFolders'].append({"id": "<managed_folder_ID>"}) export_options['includedSavedModels'].append({"id": "<model_ID>"}) settings.save() # Setting bundleID bundle_id = "version_" + str(current_vers) # Creating bundle try: proj.export_bundle(bundle_id) print(f"The bundle with ID {bundle_id} was created successfully") except: print("There was an error creating the bundle. See the traceback:") raise # Increasing the count of the version variable: proj_vars['standard']['version'] = current_vers + 1 proj.set_variables(proj_vars) print("Increased the count for the version")
Hope you will find it useful.
Answers
-
Thanks
it works i had only to add this two lines to create the exportOptions dict
settings.get_raw()["bundleExporterSettings"] = {} settings.get_raw()["bundleExporterSettings"]["exportOptions"] = {}