Key Values

Key values associated with a DataRobot model, deployment, job or other DataRobot entities are key-value pairs containing information about the related entity. Each key-value pair has the following:

  • Name: The unique and descriptive name of the key (for the model package or version).

  • Value type: The data type of the value associated with the key. The possible types are string, numeric, boolean, URL, image, dataset, pickle, binary, JSON, or YAML.

  • Category: The type of model information provided by the key value. The possible types are training parameter, metric, tag, artifact, and runtime parameter.

  • Value: The stored data or file.

You can include string, numeric, boolean, image, and dataset key values in custom compliance documentation templates.

In addition, with key values for registered models, when you generate compliance documentation for a model package and reference a supported key value in the template, DataRobot inserts the matching values from the associated model package.

Manage Key Values

Use the following commands to manage key values:

Create a Key Value

To create a key value, use dr.KeyValue.create, as shown in the following example:

import datarobot as dr

registered_model_id = "65ccb597732422fa2297199e"

key_value = dr.KeyValue.create(
    registered_model_id,
    dr.KeyValueEntityType.REGISTERED_MODEL,
    "my-kv-name",
    dr.KeyValueCategory.TAG,
    dr.KeyValueType.STRING,
    "tag-name",
)

key_value.id
>>> '65f32822be17d11dec9ebdfb'

List Key Values

To list all key values available to the current user, use dr.KeyValue.list, as in the following example:

import datarobot as dr

registered_model_id = "65ccb597732422fa2297199e"

key_values = dr.KeyValue.list(registered_model_id, dr.KeyValueEntityType.REGISTERED_MODEL)

key_values
>>> [KeyValue('my-kv-name')]

Retrieve Key Value

To get a key value by unique identifier, use dr.KeyValue.get, as in the following example:

import datarobot as dr

key_value = dr.KeyValue.get("65f32822be17d11dec9ebdfb")

key_value
>>> KeyValue('my-kv-name')

Find Key Value By Name

To find a key value by name, use dr.KeyValue.find. Provide the entity ID, entity type, and key value name, as in the following example:

import datarobot as dr

key_value = dr.KeyValue.find("65f32822be17d11dec9ebdfb", dr.KeyValueEntityType.REGISTERED_MODEL, "my-kv-name")

key_value
>>> KeyValue('my-kv-name')

Update Key Value

To get a key value by unique identifier and update it, use dr.KeyValue.get() and then update(), as in the following example:

import datarobot as dr

key_value = dr.KeyValue.get("65f32822be17d11dec9ebdfb")

key_value.update(value=4.7)
key_value.update(value_type=dr.KeyValueType.STRING, value="abc")
key_value.update(name="new-kv-name")

Get Key Value Data

To get the value from a key value, use dr.KeyValue.get_value(). Provide the key value ID, as in the following example:

import datarobot as dr

key_value = dr.KeyValue.get("65f32822be17d11dec9ebdfb")

key_value.update(value=4.7)
key_value.get_value()
>>> 4.7

key_value.update(value_type=dr.KeyValueType.STRING, value="abc")
key_value.get_value()
>>> "abc"

key_value.update(value_type=dr.KeyValueType.BOOLEAN, value=True)
key_value.get_value()
>>> True

Delete Key Value

To get a key value by unique identifier and delete it, use dr.KeyValue.get() and then delete(), as in the following example:

import datarobot as dr

key_value = dr.KeyValue.get("65f32822be17d11dec9ebdfb")
key_value.delete()