# Key values
URL: https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/key_values.html

> Manage key-value configuration for models, deployments, and other entities with the Python API client.

# 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`:

```
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`:

```
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 a key value

To get a key value by unique identifier, use `dr.KeyValue.get`:

```
import datarobot as dr

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

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

### Find key values by name

To find a key value by name, use `dr.KeyValue.find`. Provide the entity ID, entity type, and key value name:

```
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 values

To get a key value by unique identifier and update it, use `dr.KeyValue.get()` and then `update()`:

```
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:

```
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 values

To get a key value by unique identifier and delete it, use `dr.KeyValue.get()` and then `delete()`:

```
import datarobot as dr

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

---
