# Custom models
URL: https://docs.datarobot.com/en/docs/api/reference/sdk/custom-models.html

# Custom models

### class datarobot.models.custom_model_version.CustomModelFileItem

A file item attached to a DataRobot custom model version.

Added in version v2.21.

- Variables:

### class datarobot.CustomInferenceModel

A custom inference model.

Added in version v2.21.

- Variables:

#### classmethod list(is_deployed=None, search_for=None, order_by=None)

List custom inference models available to the user.

Added in version v2.21.

- Parameters:
- Returns: A list of custom inference models.
- Return type: List[CustomInferenceModel]
- Raises:

#### classmethod get(custom_model_id)

Get custom inference model by id.

Added in version v2.21.

- Parameters: custom_model_id ( str ) – The ID of the custom inference model.
- Returns: Retrieved custom inference model.
- Return type: CustomInferenceModel
- Raises:

#### download_latest_version(file_path)

Download the latest custom inference model version.

Added in version v2.21.

- Parameters: file_path ( str ) – Path to create a file with custom model version content.
- Raises:
- Return type: None

#### classmethod create(name, target_type, target_name=None, language=None, description=None, positive_class_label=None, negative_class_label=None, prediction_threshold=None, class_labels=None, class_labels_file=None, network_egress_policy=None, maximum_memory=None, replicas=None, is_training_data_for_versions_permanently_enabled=None)

Create a custom inference model.

Added in version v2.21.

- Parameters:
- Returns: Created a custom inference model.
- Return type: CustomInferenceModel
- Raises:

#### classmethod copy_custom_model(custom_model_id)

Create a custom inference model by copying existing one.

Added in version v2.21.

- Parameters: custom_model_id ( str ) – The ID of the custom inference model to copy.
- Returns: Created a custom inference model.
- Return type: CustomInferenceModel
- Raises:

#### update(name=None, language=None, description=None, target_name=None, positive_class_label=None, negative_class_label=None, prediction_threshold=None, class_labels=None, class_labels_file=None, is_training_data_for_versions_permanently_enabled=None)

Update custom inference model properties.

Added in version v2.21.

- Parameters:
- Raises:
- Return type: None

#### refresh()

Update custom inference model with the latest data from server.

Added in version v2.21.

- Raises:
- Return type: None

#### delete()

Delete custom inference model.

Added in version v2.21.

- Raises:
- Return type: None

#### assign_training_data(dataset_id, partition_column=None, max_wait=600)

Assign training data to the custom inference model.

Added in version v2.21.

- Parameters:
- Raises:
- Return type: None

#### get_access_list()

Retrieve access control settings of this custom model.

Added in version v2.36.

- Return type: list of SharingAccess

#### share(access_list)

Update the access control settings of this custom model.

Added in version v2.36.

- Parameters: access_list ( list of SharingAccess ) – A list of SharingAccess to update.
- Raises:
- Return type: None

> [!NOTE] Examples
> Transfer access to the custom model from [old_user@datarobot.com](mailto:old_user@datarobot.com) to [new_user@datarobot.com](mailto:new_user@datarobot.com)
> 
> ```
> import datarobot as dr
> 
> new_access = dr.SharingAccess(new_user@datarobot.com,
>                               dr.enums.SHARING_ROLE.OWNER, can_share=True)
> access_list = [dr.SharingAccess(old_user@datarobot.com, None), new_access]
> 
> dr.CustomInferenceModel.get('custom-model-id').share(access_list)
> ```

### class datarobot.CustomModelTest

An custom model test.

Added in version v2.21.

- Variables:

#### classmethod create(custom_model_id, custom_model_version_id, dataset_id=None, max_wait=600, network_egress_policy=None, maximum_memory=None, replicas=None)

Create and start a custom model test.

Added in version v2.21.

- Parameters:
- Returns: created custom model test
- Return type: CustomModelTest
- Raises:

#### classmethod list(custom_model_id)

List custom model tests.

Added in version v2.21.

- Parameters: custom_model_id ( str ) – the ID of the custom model
- Returns: a list of custom model tests
- Return type: List[CustomModelTest]
- Raises:

#### classmethod get(custom_model_test_id)

Get custom model test by id.

Added in version v2.21.

- Parameters: custom_model_test_id ( str ) – the ID of the custom model test
- Returns: retrieved custom model test
- Return type: CustomModelTest
- Raises:

#### get_log()

Get log of a custom model test.

Added in version v2.21.

- Raises:

#### get_log_tail()

Get log tail of a custom model test.

Added in version v2.21.

- Raises:

#### cancel()

Cancel custom model test that is in progress.

Added in version v2.21.

- Raises:

#### refresh()

Update custom model test with the latest data from server.

Added in version v2.21.

- Raises:

### class datarobot.CustomModelVersion

A version of a DataRobot custom model.

Added in version v2.21.

- Variables:

#### classmethod from_server_data(data, keep_attrs=None)

Instantiate an object of this class using the data directly from the server,
meaning that the keys may have the wrong camel casing

- Parameters:
- Return type: CustomModelVersion

#### classmethod create_clean(custom_model_id, base_environment_id=None, is_major_update=True, folder_path=None, files=None, network_egress_policy=None, maximum_memory=None, replicas=None, required_metadata_values=None, training_dataset_id=None, partition_column=None, holdout_dataset_id=None, keep_training_holdout_data=None, max_wait=600, runtime_parameter_values=None, base_environment_version_id=None)

Create a custom model version without files from previous versions.

> Create a version with training or holdout data:
> If training/holdout data related parameters are provided,
> the training data is assigned asynchronously.
> In this case:
> * if max_wait is not None, the function returns once the job is finished.
> * if max_wait is None, the function returns immediately. Progress can be polled by the user (see examples).If training data assignment fails, new version is still created,
> but it is not allowed to create a model package (version) for the model version and to deploy it.
> To check for training data assignment error, check version.training_data.assignment_error[“message”].

Added in version v2.21.

- Parameters:
- Returns: Created custom model version.
- Return type: CustomModelVersion
- Raises:

> [!NOTE] Examples
> Create a version with blocking (default max_wait=600) training data assignment:
> 
> ```
> import datarobot as dr
> from datarobot.errors import TrainingDataAssignmentError
> 
> dr.Client(token=my_token, endpoint=endpoint)
> 
> try:
>     version = dr.CustomModelVersion.create_clean(
>         custom_model_id="6444482e5583f6ee2e572265",
>         base_environment_id="642209acc563893014a41e24",
>         training_dataset_id="6421f2149a4f9b1bec6ad6dd",
>     )
> except TrainingDataAssignmentError as e:
>     print(e)
> ```
> 
> Create a version with non-blocking training data assignment:
> 
> ```
> import datarobot as dr
> 
> dr.Client(token=my_token, endpoint=endpoint)
> 
> version = dr.CustomModelVersion.create_clean(
>     custom_model_id="6444482e5583f6ee2e572265",
>     base_environment_id="642209acc563893014a41e24",
>     training_dataset_id="6421f2149a4f9b1bec6ad6dd",
>     max_wait=None,
> )
> 
> while version.training_data.assignment_in_progress:
>     time.sleep(10)
>     version.refresh()
> if version.training_data.assignment_error:
>     print(version.training_data.assignment_error["message"])
> ```

#### classmethod create_from_previous(custom_model_id, base_environment_id=None, is_major_update=True, folder_path=None, files=None, files_to_delete=None, network_egress_policy=None, maximum_memory=None, replicas=None, required_metadata_values=None, training_dataset_id=None, partition_column=None, holdout_dataset_id=None, keep_training_holdout_data=None, max_wait=600, runtime_parameter_values=None, base_environment_version_id=None, runtime_parameters=None)

Create a custom model version containing files from a previous version.

> Create a version with training/holdout data:
> If training/holdout data related parameters are provided,
> the training data is assigned asynchronously.
> In this case:
> * if max_wait is not None, function returns once job is finished.
> * if max_wait is None, function returns immediately, progress can be polled by the user, see examples.If training data assignment fails, new version is still created,
> but it is not allowed to create a model package (version) for the model version and to deploy it.
> To check for training data assignment error, check version.training_data.assignment_error[“message”].

Added in version v2.21.

- Parameters:
- Returns: created custom model version
- Return type: CustomModelVersion
- Raises:

> [!NOTE] Examples
> Create a version with blocking (default max_wait=600) training data assignment:
> 
> ```
> import datarobot as dr
> from datarobot.errors import TrainingDataAssignmentError
> 
> dr.Client(token=my_token, endpoint=endpoint)
> 
> try:
>     version = dr.CustomModelVersion.create_from_previous(
>         custom_model_id="6444482e5583f6ee2e572265",
>         base_environment_id="642209acc563893014a41e24",
>         training_dataset_id="6421f2149a4f9b1bec6ad6dd",
>     )
> except TrainingDataAssignmentError as e:
>     print(e)
> ```
> 
> Create a version with non-blocking training data assignment:
> 
> ```
> import datarobot as dr
> 
> dr.Client(token=my_token, endpoint=endpoint)
> 
> version = dr.CustomModelVersion.create_from_previous(
>     custom_model_id="6444482e5583f6ee2e572265",
>     base_environment_id="642209acc563893014a41e24",
>     training_dataset_id="6421f2149a4f9b1bec6ad6dd",
>     max_wait=None,
> )
> 
> while version.training_data.assignment_in_progress:
>     time.sleep(10)
>     version.refresh()
> if version.training_data.assignment_error:
>     print(version.training_data.assignment_error["message"])
> ```

#### classmethod list(custom_model_id)

List custom model versions.

Added in version v2.21.

- Parameters: custom_model_id ( str ) – The ID of the custom model.
- Returns: A list of custom model versions.
- Return type: List[CustomModelVersion]
- Raises:

#### classmethod get(custom_model_id, custom_model_version_id)

Get custom model version by id.

Added in version v2.21.

- Parameters:
- Returns: Retrieved custom model version.
- Return type: CustomModelVersion
- Raises:

#### download(file_path)

Download custom model version.

Added in version v2.21.

- Parameters: file_path ( str ) – Path to create a file with custom model version content.
- Raises:
- Return type: None

#### update(description=None, required_metadata_values=None)

Update custom model version properties.

Added in version v2.21.

- Parameters:
- Raises:
- Return type: None

#### refresh()

Update custom model version with the latest data from server.

Added in version v2.21.

- Raises:
- Return type: None

#### get_feature_impact(with_metadata=False)

Get custom model feature impact.

Added in version v2.23.

- Parameters: with_metadata ( bool ) – The flag indicating if the result should include the metadata as well.
- Returns: feature_impacts – The feature impact data. Each item is a dict with the keys ‘featureName’,
  ‘impactNormalized’, and ‘impactUnnormalized’, and ‘redundantWith’.
- Return type: list of dict
- Raises:

#### calculate_feature_impact(max_wait=600)

Calculate custom model feature impact.

Added in version v2.23.

- Parameters: max_wait ( Optional[int] ) – Max time to wait for feature impact calculation.
  If set to None - method will return without waiting.
  Defaults to 10 min
- Raises:
- Return type: None

### class datarobot.models.execution_environment.RequiredMetadataKey

Definition of a metadata key that custom models using this environment must define

Added in version v2.25.

- Variables:

### class datarobot.models.CustomModelVersionConversion

A conversion of a DataRobot custom model version.

Added in version v2.27.

- Variables:

#### classmethod run_conversion(custom_model_id, custom_model_version_id, main_program_item_id, max_wait=None)

Initiate a new custom model version conversion.

- Parameters:
- Returns: conversion_id – The ID of the newly created conversion entity.
- Return type: str
- Raises:

#### classmethod stop_conversion(custom_model_id, custom_model_version_id, conversion_id)

Stop a conversion that is in progress.

- Parameters:
- Raises:
- Return type: Response

#### classmethod get(custom_model_id, custom_model_version_id, conversion_id)

Get custom model version conversion by id.

Added in version v2.27.

- Parameters:
- Returns: Retrieved custom model version conversion.
- Return type: CustomModelVersionConversion
- Raises:

#### classmethod get_latest(custom_model_id, custom_model_version_id)

Get latest custom model version conversion for a given custom model version.

Added in version v2.27.

- Parameters:
- Returns: Retrieved latest conversion for a given custom model version.
- Return type: CustomModelVersionConversion or None
- Raises:

#### classmethod list(custom_model_id, custom_model_version_id)

Get custom model version conversions list per custom model version.

Added in version v2.27.

- Parameters:
- Returns: Retrieved conversions for a given custom model version.
- Return type: List[CustomModelVersionConversion]
- Raises:

### class datarobot.CustomModelVersionDependencyBuild

Metadata about a DataRobot custom model version’s dependency build

Added in version v2.22.

- Variables:

#### classmethod get_build_info(custom_model_id, custom_model_version_id)

Retrieve information about a custom model version’s dependency build

Added in version v2.22.

- Parameters:
- Returns: The dependency build information.
- Return type: CustomModelVersionDependencyBuild

#### classmethod start_build(custom_model_id, custom_model_version_id, max_wait=600)

Start the dependency build for a custom model version  dependency build

Added in version v2.22.

- Parameters:
- Return type: Optional [ CustomModelVersionDependencyBuild ]

#### get_log()

Get log of a custom model version dependency build.

Added in version v2.22.

- Raises:
- Return type: str

#### cancel()

Cancel custom model version dependency build that is in progress.

Added in version v2.22.

- Raises:
- Return type: None

#### refresh()

Update custom model version dependency build with the latest data from server.

Added in version v2.22.

- Raises:
- Return type: None

### class datarobot.ExecutionEnvironment

An execution environment entity.

Added in version v2.21.

- Variables:

#### classmethod create(name, description=None, programming_language=None, required_metadata_keys=None, is_public=None, use_cases=None)

Create an execution environment.

Added in version v2.21.

- Parameters:
- Returns: created execution environment
- Return type: ExecutionEnvironment
- Raises:

#### classmethod list(search_for=None, is_own=None, use_cases=None, is_public=None, offset=0, limit=0)

List execution environments available to the user.

Added in version v2.21.

- Parameters:
- Returns: a list of execution environments.
- Return type: List[ExecutionEnvironment]
- Raises:

#### classmethod get(execution_environment_id)

Get execution environment by its ID.

Added in version v2.21.

- Parameters: execution_environment_id ( str ) – ID of the execution environment to retrieve
- Returns: retrieved execution environment
- Return type: ExecutionEnvironment
- Raises:

#### delete()

Delete execution environment.

Added in version v2.21.

- Raises:
- Return type: None

#### update(name=None, description=None, required_metadata_keys=None, is_public=None, use_cases=None)

Update execution environment properties.

Added in version v2.21.

- Parameters:
- Raises:
- Return type: None

#### refresh()

Update execution environment with the latest data from server.

Added in version v2.21.

- Raises:
- Return type: None

#### get_access_list()

Retrieve access control settings of this environment.

Added in version v2.36.

- Return type: list of SharingAccess

#### share(access_list)

Update the access control settings of this execution environment.

Added in version v2.36.

- Parameters: access_list ( list of SharingAccess ) – A list of SharingAccess to update.
- Raises:
- Return type: None

> [!NOTE] Examples
> Transfer access to the execution environment from [old_user@datarobot.com](mailto:old_user@datarobot.com) to [new_user@datarobot.com](mailto:new_user@datarobot.com)
> 
> ```
> import datarobot as dr
> 
> new_access = dr.SharingAccess(new_user@datarobot.com,
>                               dr.enums.SHARING_ROLE.OWNER, can_share=True)
> access_list = [dr.SharingAccess(old_user@datarobot.com, None), new_access]
> 
> dr.ExecutionEnvironment.get('environment-id').share(access_list)
> ```

### class datarobot.ExecutionEnvironmentVersion

A version of a DataRobot execution environment.

Added in version v2.21.

- Variables:

#### classmethod create(execution_environment_id, docker_context_path=None, docker_image_uri=None, label=None, description=None, max_wait=600)

Create an execution environment version.

Added in version v2.21.

- Parameters:
- Returns: created execution environment version
- Return type: ExecutionEnvironmentVersion
- Raises:

#### classmethod list(execution_environment_id, build_status=None)

List execution environment versions available to the user.
.. versionadded:: v2.21

- Parameters:
- Returns: a list of execution environment versions.
- Return type: List[ExecutionEnvironmentVersion]
- Raises:

#### classmethod get(execution_environment_id, version_id)

Get execution environment version by id.

Added in version v2.21.

- Parameters:
- Returns: retrieved execution environment version
- Return type: ExecutionEnvironmentVersion
- Raises:

#### download(file_path)

Download execution environment version.

Added in version v2.21.

- Parameters: file_path ( str ) – path to create a file with execution environment version content
- Returns: retrieved execution environment version
- Return type: ExecutionEnvironmentVersion
- Raises:

#### get_build_log()

Get execution environment version build log and error.

Added in version v2.21.

- Returns: retrieved execution environment version build log and error.
  If there is no build error - None is returned.
- Return type: Tuple[str , str]
- Raises:

#### refresh()

Update execution environment version with the latest data from server.

Added in version v2.21.

- Raises:
- Return type: None

### class datarobot.models.custom_model_version.HoldoutData

Holdout data assigned to a DataRobot custom model version.

Added in version v3.2.

- Variables:

### class datarobot.models.custom_model_version.TrainingData

Training data assigned to a DataRobot custom model version.

Added in version v3.2.

- Variables:

### class datarobot.models.custom_model_version.RuntimeParameter

Definition of a runtime parameter used for the custom model version, it includes
: the override value if provided.

Added in version v3.4.0.

- Variables:

#### to_dict()

Serialize this parameter for use in the `runtime_parameters` creation argument.

Returns a dict with snake_case keys that are converted to camelCase before sending to
the API. Only fields relevant to parameter creation are included; server-computed fields
( `override_value`, `key_value_id`) are excluded. Optional fields with a `None` value are omitted so the server applies its own defaults.

- Return type: Dict [ str , Any ]

### class datarobot.models.custom_model_version.RuntimeParameterValue

The definition of a runtime parameter value used for the custom model version, this defines
the runtime parameter override.

Added in version v3.4.0.

- Variables:

---
