API Deployer#

class dataikuapi.dss.apideployer.DSSAPIDeployer(client)#

Handle to interact with the API Deployer.

Do not create this directly, use dataikuapi.dss.DSSClient.get_apideployer()

list_deployments(as_objects=True)#

Lists deployments on the API Deployer

Parameters:

as_objects (boolean) – if True, returns a list of DSSAPIDeployerDeployment, else returns a list of dict. Each dict contains at least a field “id” indicating the identifier of this deployment

Returns:

a list - see as_objects for more information

Return type:

list

get_deployment(deployment_id)#

Returns a handle to interact with a single deployment, as a DSSAPIDeployerDeployment

Parameters:

deployment_id (str) – Identifier of the deployment to get

Return type:

DSSAPIDeployerDeployment

create_deployment(deployment_id, service_id, infra_id, version, endpoint_id=None, ignore_warnings=False, authorizations_to_query_through_deployer=None)#

Creates a deployment and returns the handle to interact with it. The returned deployment is not yet started and you need to call start_update()

Parameters:
  • deployment_id (str) – Identifier of the deployment to create

  • service_id (str) – Identifier of the API Service to target

  • infra_id (str) – Identifier of the deployment infrastructure to use

  • version (str) – Identifier of the API Service version to deploy

  • endpoint_id (str) – Identifier of the endpoint to deploy if you use a Deploy Anywhere infra. Ignored otherwise

  • ignore_warnings (boolean) – Ignore warnings concerning the governance status of the model version(s) to deploy

  • authorizations_to_query_through_deployer (list) – List of group authorizations allowing query-through-deployer.

Each item is a dict with keys:
  • “group”: name of the group

  • “queryThroughDeployer”: boolean indicating if the group can query through the deployer

Example:

authorizations_to_query_through_deployer = [
    {
        "group": "administrators",
        "queryThroughDeployer": True
    }
]
Return type:

DSSAPIDeployerDeployment

list_stages()#

Lists infrastructure stages of the API Deployer

Return type:

list of dict. Each dict contains a field “id” for the stage identifier and “desc” for its description.

Return type:

list

list_infras(as_objects=True)#

Lists deployment infrastructures on the API Deployer

Parameters:

as_objects (boolean) – if True, returns a list of DSSAPIDeployerInfra, else returns a list of dict. Each dict contains at least a field “id” indicating the identifier of this infra

Returns:

a list - see as_objects for more information

Return type:

list

create_infra(infra_id, stage, type, govern_check_policy='NO_CHECK')#

Creates a new infrastructure on the API Deployer and returns the handle to interact with it.

Parameters:
  • infra_id (str) – Unique Identifier of the infra to create

  • stage (str) – Infrastructure stage. Stages are configurable on each API Deployer

  • type (str) – STATIC, K8S, AZURE_ML, SAGEMAKER, SNOWPARK or VERTEX_AI

  • govern_check_policy (str) – PREVENT, WARN, or NO_CHECK depending if the deployer will check whether the saved model versions deployed on this infrastructure has to be managed and approved in Dataiku Govern

Return type:

DSSAPIDeployerInfra

get_infra(infra_id)#

Returns a handle to interact with a single deployment infra, as a DSSAPIDeployerInfra

Parameters:

infra_id (str) – Identifier of the infra to get

Return type:

DSSAPIDeployerInfra

list_services(as_objects=True)#

Lists API services on the API Deployer

Parameters:

as_objects (boolean) – if True, returns a list of DSSAPIDeployerService, else returns a list of dict. Each dict contains at least a field “id” indicating the identifier of this Service

Returns:

a list - see as_objects for more information

Return type:

list

create_service(service_id)#

Creates a new API Service on the API Deployer and returns the handle to interact with it.

Parameters:

service_id (str) – Identifier of the API Service to create

Return type:

DSSAPIDeployerService

get_service(service_id)#

Returns a handle to interact with a single service, as a DSSAPIDeployerService

Parameters:

service_id (str) – Identifier of the API service to get

Return type:

DSSAPIDeployerService

Infrastructures#

class dataikuapi.dss.apideployer.DSSAPIDeployerInfra(client, infra_id)#

An API Deployer infrastructure.

Do not create this directly, use get_infra()

property id#
get_status()#

Returns status information about this infrastructure

Return type:

dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus

get_settings()#

Gets the settings of this infra. If you want to modify the settings, you need to call save() on the returned object

Returns:

a dataikuapi.dss.apideployer.DSSAPIDeployerInfraSettings

delete()#

Deletes this infra You may only delete an infra if it has no deployments on it anymore.

class dataikuapi.dss.apideployer.DSSAPIDeployerInfraSettings(client, infra_id, settings)#

The settings of an API Deployer infrastructure

Do not create this directly, use get_settings()

get_type()#

Gets the type of this infra

Returns:

the type of this infra

Return type:

string

add_apinode(url, api_key, graphite_prefix=None)#

Adds an API node to the list of nodes of this infra.

Only applicable to STATIC infrastructures

Parameters:
  • url (str) – url of the API node that will be added to this infra

  • api_key (str) – api key secret to connect to the API node

  • graphite_prefix (str) – graphite prefix for metric reports if graphite is configured

remove_apinode(node_url)#

Removes a node from the list of nodes of this infra. Only applicable to STATIC infrastructures

Parameters:

node_url (str) – URL of the node to remove

get_raw()#

Gets the raw settings of this infra. This returns a reference to the raw settings, not a copy, so changes made to the returned object will be reflected when saving.

Return type:

dict

save()#

Saves back these settings to the infra

class dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus(client, infra_id, light_status)#

The status of an API Deployer infrastructure.

Do not create this directly, use get_status()

get_deployments()#

Returns the deployments that are deployed on this infrastructure

Returns:

a list of deployments

Return type:

list of dataikuapi.dss.apideployer.DSSAPIDeployerDeployment

get_raw()#

Gets the raw status information. This returns a dictionary with various information about the infrastructure

Return type:

dict

API Services#

class dataikuapi.dss.apideployer.DSSAPIDeployerService(client, service_id)#

An API service on the API Deployer

Do not create this directly, use get_service()

property id#
get_status()#

Returns status information about this service. This is used mostly to get information about which versions are available and which deployments are exposing this service

Return type:

dataikuapi.dss.apideployer.DSSAPIDeployerServiceStatus

import_version(fp)#

Imports a new version for an API service from a file-like object pointing to a version package Zip file

Parameters:

fp (string) – A file-like object pointing to a version package Zip file

get_settings()#

Gets the settings of this service. If you want to modify the settings, you need to call save() on the returned object.

The main things that can be modified in a service settings are permissions

Returns:

a dataikuapi.dss.apideployer.DSSAPIDeployerServiceSettings

delete_version(version)#

Deletes a version from this service

Parameters:

version (string) – The version to delete

get_version_stream(version_id)#

Download a version of a service as a stream.

The archive of this version can then be deployed in a DSS API Node.

Warning

This call will monopolize the DSSClient until the stream it returns is closed.

with api_deployer_service.get_version_stream('v1') as fp:
    # use fp

# or explicitly close the stream after use
fp = api_deployer_service.get_version_stream('v1')
# use fp, then close
fp.close()
Parameters:

version_id (string) – version (identifier) of the package to download

Returns:

the package archive, as an HTTP stream

Return type:

file-like

download_version_to_file(version_id, path)#

Download an archive of a version to a local file.

The archive can then be deployed in a DSS API Node.

Parameters:
  • version_id (string) – version (identifier) of the package to download

  • path (string) – absolute or relative path to a file in which the package is downloaded

delete()#

Deletes this service

You may only delete a service if it has no deployments on it anymore.

class dataikuapi.dss.apideployer.DSSAPIDeployerServiceSettings(client, service_id, settings)#

The settings of an API Deployer Service.

Do not create this directly, use get_settings()

get_raw()#

Gets the raw settings of this deployment. This returns a reference to the raw settings, not a copy, so changes made to the returned object will be reflected when saving.

Return type:

dict

save()#

Saves back these settings to the API service

class dataikuapi.dss.apideployer.DSSAPIDeployerServiceStatus(client, service_id, light_status)#

The status of an API Deployer Service.

Do not create this directly, use get_status()

get_deployments(infra_id=None)#

Returns the deployments that have been created from this published project

Parameters:

infra_id (str) – Identifier of an infra, allows to only keep in the returned list the deployments on this infra. If not set, the list contains all the deployments using this published project, across every infra of the Project Deployer.

Returns:

a list of deployments

Return type:

list of dataikuapi.dss.apideployer.DSSAPIDeployerDeployment

get_versions()#

Returns the versions of this service that have been published on the API Service

Each version is a dict that contains at least a “id” field, which is the version identifier

Returns:

a list of versions, each as a dict containing a “id” field

Return type:

list of dicts

get_raw()#

Gets the raw status information. This returns a dictionary with various information about the service,

Return type:

dict

Deployments#

class dataikuapi.dss.apideployer.DSSAPIDeployerDeployment(client, deployment_id)#

A Deployment on the API Deployer

Do not create this directly, use get_deployment()

property id#
get_status()#

Returns status information about this deployment

Return type:

dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentStatus

get_governance_status(version='')#

Returns the governance status about this deployment if applicable It covers all the embedded model versions

Parameters:

version (str) – (Optional) The specific package version of the published service to get status from. If empty, consider all the versions used in the deployment generation mapping.

Return type:

dict InforMessages containing the governance status

get_settings()#

Gets the settings of this deployment. If you want to modify the settings, you need to call save() on the returned object

Returns:

a dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentSettings

start_update()#

Starts an asynchronous update of this deployment to try to match the actual state to the current settings

Returns:

a dataikuapi.dss.future.DSSFuture tracking the progress of the update. Call wait_for_result() on the returned object to wait for completion (or failure)

delete(disable_first=False, ignore_pre_delete_errors=False)#

Deletes this deployment. The disable_first flag automatically disables the deployment before its deletion.

Parameters:
  • disable_first (boolean) – If True, automatically disables this deployment before deleting it. If False, will raise an Exception if this deployment is enabled.

  • ignore_pre_delete_errors (boolean) – If True, any error occurred during the actions performed previously to delete the deployment will be ignored and the delete action will be performed anyway.

get_open_api()#

Gets the OpenAPI document of this deployment if it’s available or raise a 404 error.

Returns:

a dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentOpenApi

run_test_queries(endpoint_id=None, test_queries=None)#

Runs test queries on a deployment and returns results as a dict

Parameters:
  • endpoint_id (str) – Mandatory if the deployment has multiple endpoints

  • test_queries (list) – Queries as str, formatted as [{“q”: {“features”: {“feat_1”: “value”, …}}, {…}, … ]. If left to None, the test queries of the current version of the service will be used.

Return type:

dict

Usage example

import dataiku

client = dataiku.api_client()
deployer = client.get_apideployer()
deployment = deployer.get_deployment('service14');

test_queries = [{'q': {'features': {
    'Pclass': '200',
    'Sex': 'male',
    'Age': '22',
    'Embarked': 'S'
}}}]

# run existing test queries on deployment endpoint (if unique, else error)
test_queries_result = deployment.run_test_queries()

# run specified test queries on deployment "survived" endpoint
test_queries_result = deployment.run_test_queries(endpoint_id="survived", test_queries=test_queries)

# run existing test queries on deployment  "survived" endpoint
test_queries_result = deployment.run_test_queries(endpoint_id="survived")

# run specified test queries on deployment endpoint (if unique, else error)
test_queries_result = deployment.run_test_queries(test_queries=test_queries)
list_updates()#

Retrieves a list of available deployment updates. Each element contains start timestamp, type and status fields

Returns:

a list of deployment updates

Return type:

list of dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentUpdateListItem

get_update(timestamp=None)#

Retrieves a specific deployment update by timestamp, or the most recent update if no timestamp is provided

Parameters:

timestamp ((optional) string) – The timestamp that uniquely identifies the update to retrieve

Return type:

dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentUpdate

run_queries(queries, endpoint_id=None, adapt_query_for_infra_type=True)#

Runs queries on a deployment and returns results as a dict An authorization to query the deployment through the deployer is needed

Parameters:
  • queries (list) – Queries as str, formatted as [{"q": {"features": {"feat_1": "value", ...}}, {...}, ... ].

  • endpoint_id (str) – Mandatory if the deployment has multiple endpoints

  • adapt_query_for_infra_type (bool) – If True, automatically adjusts the query format to be compatible with the target infrastructure type. This is mainly applicable to Deploy-Anywhere infrastructures. Defaults to True.

Return type:

dict

Usage example

import dataiku

client = dataiku.api_client()
deployer = client.get_apideployer()
deployment = deployer.get_deployment('service14');

queries = [{'q': {'features': {
    'Pclass': '200',
    'Sex': 'male',
    'Age': '22',
    'Embarked': 'S'
}}}]

# run queries on deployment "survived" endpoint
queries_results = deployment.run_queries(endpoint_id="survived")

# run queries on deployment endpoint (if unique, else error)
queries_results = deployment.run_queries(queries)
class dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentSettings(client, deployment_id, settings)#

The settings of an API Deployer deployment.

Do not create this directly, use get_settings()

get_raw()#

Gets the raw settings of this deployment. This returns a reference to the raw settings, not a copy, so changes made to the returned object will be reflected when saving.

Return type:

dict

set_enabled(enabled)#

Enables or disables this deployment

Parameters:

enabled (bool) – True/False to Enable/Disable this deployment

set_single_version(version)#

Sets this deployment to target a single version of the API service

Parameters:

version (str) – Identifier of the version to set

save(ignore_warnings=False)#

Saves back these settings to the deployment

Parameters:

ignore_warnings (boolean) – ignore warnings concerning the governance status of the model version(s) to deploy

class dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentStatus(client, deployment_id, light_status, heavy_status)#

The status of an API Deployer deployment.

Do not create this directly, use get_status()

get_light()#

Gets the ‘light’ (summary) status. This returns a dictionary with various information about the deployment, but not the actual health of the deployment

Return type:

dict

get_heavy()#

Gets the ‘heavy’ (full) status. This returns a dictionary with various information about the deployment

Return type:

dict

get_service_urls()#

Returns service-level URLs for this deployment (ie without the enpdoint-specific suffix)

Returns:

a list of service-level URLs for this deployment

Return type:

list

get_health()#

Returns the health of this deployment as a string

Returns:

HEALTHY if the deployment is working properly, various other status otherwise

Return type:

string

get_health_messages()#

Returns messages about the health of this deployment

class dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentOpenApi(open_api_doc_json)#

The OpenAPI document of an API Deployer deployment.

Do not create this directly, use get_open_api()

get()#

Gets the OpenAPI document as dict.

Return type:

dict

get_raw()#

Gets the OpenAPI document raw.

Return type:

string

class dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentUpdate(update)#

Represents an API Deployer’s deployment update.

This class should not be instantiated directly. Use get_update() to obtain instances of this class

property start_time#
property end_time#
property requester#
property status#
property logs#
Returns the logs for this update as a list of lines:
  • Each line represents a single log entry

  • The list preserves the original order of the log output

Returns:

List of log lines, or None if no logs are available

Return type:

list[str] or None

get_raw()#

Returns the raw data of this deployment update as a dictionary

Returns:

a deployment update, as a dict

Return type:

dict

class dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentUpdateListItem(client, deployment_id, data)#

Represents a single item in a list of API Deployer’s deployment updates.

This class should not be instantiated directly. Instead, use list_updates() to retrieve instances of this class.

property start_time#
property type#
property status#
get_raw()#

Returns the raw dictionary representation of this deployment update list item

Returns:

a deployment update list item, as a dict

Return type:

dict

get_full_update()#

Returns the full deployment update corresponding to this list item, as a DSSAPIDeployerDeploymentUpdate

Returns:

a fully detailed deployment update

Return type:

DSSAPIDeployerDeploymentUpdate