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

Create Bundle which includes contents with Python API

Solved!
MYassine
Level 1
Create Bundle which includes contents with Python API

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

0 Kudos
1 Solution
sergeyd
Dataiker
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. 

View solution in original post

2 Replies
sergeyd
Dataiker
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. 

MYassine
Level 1
Author

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"] = {}
0 Kudos

Labels

?
Labels (1)
A banner prompting to get Dataiku