Managing code envs

The API offers methods to:

  • Create code envs
  • Read and write settings and packages of code envs
  • Update code envs
  • Reinstall

Creating a code env

Python 3.6 code env, with Jupyter support

client = dataiku.api_client()

# Create the code env
code_env = client.create_code_env("PYTHON", "my_code_env_name", "DESIGN_MANAGED", {"pythonInterpreter": "PYTHON36"})

# Setup packages to install
definition = code_env.get_definition()
definition["desc"]["installCorePackages"] = True
definition["desc"]["installJupyterSupport"] = True

# We want to install 2 packages (tabulate and nameparser)
definition["specPackageList"] = "tabulate\nnameparser"

# Save the new settings
code_env.set_definition(definition)

# Actually perform the installation
code_env.update_packages()
code_env.set_jupyter_support(True)

Python 2.7 code env, without Jupyter support

client = dataiku.api_client()

# Create the code env
code_env = client.create_code_env("PYTHON", "my_code_env_name", "DESIGN_MANAGED")

# Setup packages to install
definition = code_env.get_definition()
definition["desc"]["installCorePackages"] = True

# We want to install 2 packages (tabulate and nameparser)
definition["specPackageList"] = "tabulate\nnameparser"

# Save the new settings
code_env.set_definition(definition)

# Actually perform the installation
code_env.update_packages()

Reference documentation

class dataikuapi.dss.admin.DSSCodeEnv(client, env_lang, env_name)

A code env on the DSS instance. Do not create this directly, use dataikuapi.DSSClient.get_code_env()

delete()

Delete the code env Note: this call requires an API key with admin rights

get_definition()

Get the code env’s definition

Note: this call requires an API key with admin rights

Returns:the code env definition, as a dict
set_definition(env)

Set the code env’s definition. The definition should come from a call to get_definition()

Fields that can be updated in design node:

  • env.permissions, env.usableByAll, env.desc.owner
  • env.specCondaEnvironment, env.specPackageList, env.externalCondaEnvName, env.desc.installCorePackages, env.desc.installJupyterSupport, env.desc.yarnPythonBin

Fields that can be updated in automation node (where {version} is the updated version):

  • env.permissions, env.usableByAll, env.owner
  • env.{version}.specCondaEnvironment, env.{version}.specPackageList, env.{version}.externalCondaEnvName, env.{version}.desc.installCorePackages, env.{version}.desc.installJupyterSupport, env.{version}.desc.yarnPythonBin

Note: this call requires an API key with admin rights

Parameters:data (dict) – a code env definition
Returns:the updated code env definition, as a dict
set_jupyter_support(active)

Update the code env jupyter support

Note: this call requires an API key with admin rights

Parameters:active – True to activate jupyter support, False to deactivate
update_packages()

Update the code env packages so that it matches its spec

Note: this call requires an API key with admin rights