sasctl.services.model_repository#
The Model Repository service supports registering and managing models.
- class sasctl._services.model_repository.ModelRepository[source]#
Bases:
Service
Implements the Model Repository REST API.
The Model Repository API provides support for registering, organizing, and managing models within a common model repository.
See also
- classmethod add_model_content(model, file, name, role=None, content_type='multipart/form-data')[source]#
Add additional files to the model.
- Parameters:
model (str or dict) – The name or id of the model, or a dictionary representation of the model.
file (str, dict, or bytes) – A file related to the model, such as the model code.
name (str) – Name of the file related to the model.
role (str) – Role of the model file, such as ‘Python pickle’. Default value is None.
content_type (str) – An HTTP Content-Type value. Default value is multipart/form-data.
- Returns:
str – The model content schema.
- classmethod convert_python_to_ds2(model)[source]#
Converts a Python model to DS2
For SAS Viya 3.5 Python models on SAS Model Manager, wrap the Python score code in DS2 and convert the model score code type to DS2. Models converted in this way are not scoreable by CAS.
- classmethod copy_analytic_store(model)[source]#
Copy model ASTOREs to a pre-defined server location.
Copies all of the analytic stores for a model to the pre-defined server location (/config/data/modelsvr/astore). To enable publishing and scoring, models that contain analytic stores need the ASTORE files to be copied to a set location (/config/data/modelsrv/astore). This location is used for integration with Event Stream Processing and others. This request invokes an asynchronous call to copy the analytic store files. Check the individual analytic store uris to get the completion state: pending, copying, success, failure. Please review the full Model Manager documentation before using.
- classmethod copy_python_resources(model)[source]#
Moves a model’s score resources to the Compute server.
Copies all of the Python score resources for a model to the pre-defined server location (/models/resources/viya/<model-UUID>/). To enable publishing and scoring, models that contain Python scoring resources need the score resource files to be copied to a set location (/models/resources/viya/<model-UUID>/). This location is used for integration with Event Stream Processing and others. This request invokes an asynchronous call to copy the score resource files. Check the individual score resource uris to get the completion state: pending, copying, success, failure. Please review the full Model Manager documentation before using.
- classmethod create_model(model, project, description=None, modeler=None, function=None, algorithm=None, tool=None, score_code_type=None, training_table=None, event_prob_variable=None, event_target_value=None, is_champion=False, is_challenger=False, location=None, target_variable=None, is_retrainable=False, is_immutable=False, properties=None, input_variables=None, output_variables=None)[source]#
Create a model in an existing project or folder.
- Parameters:
model (str or dict) – The name or id of the model, or a dictionary representation of the model.
project (str or dict) – The name or id of the model project, or a dictionary representation of the model project.
description (str, optional) – The description of the model.
modeler (str, optional) – Name of the user that created the model. Current user name will be used if unspecified.
function (str, optional) – The function of the model, valid values include: analytical, classification, cluster, forecasting, prediction, Text analytics, transformation.
algorithm (str, optional) – The name of the model algorithm.
tool (str, optional) – The name of the model tool, can be ‘Python 2’ or ‘Python 3’.
score_code_type (str, optional) – The score code type for the model.
training_table (str, optional) – The train data table.
event_prob_variable (str, optional) – The name of the event probability variable. Used for classification models only.
event_target_value (str, optional) – The target event value. Used for classification models only.
is_champion (bool, optional) – Indicates whether the model should be designated as the project’s champion model. Defaults to False.
is_challenger (bool, optional) – Indicates whether the model should be designated as a challenger model in the project. Defaults to False.
location (str, optional,) – The location of this model.
target_variable (str, optional) – The name of the target variable.
is_retrainable (bool) – Indicates whether the model can be retrained or not.
is_immutable (bool) – Indicates whether the model can be changed or not.
properties (dict, optional) – Custom model properties provided as name: value pairs. Allowed types are int, float, string, datetime.date, and datetime.datetime
input_variables (Iterable, optional) – Model input variables. By default, these are the same as the model project.
output_variables (Iterable, optional) –
- Model output variables. By default, these are the same as the model
project.
project_version (str) – Name of project version to import model in to. Default value is “latest”.
- Returns:
str – The model schema returned in JSON format.
- classmethod create_model_version(model, minor=False)[source]#
Create a new version of an existing model.
Create a new major (X.0) or minor (1.X) version of an existing model. All contents from the current version are copied to the new version.
- Parameters:
- Returns:
RestObj – The new version of the model.
- classmethod create_project(project, repository, **kwargs)[source]#
Create a model project in the given model repository.
- classmethod delete_model(item)#
Delete a model instance.
- Parameters:
item
- Returns:
None
- classmethod delete_project(item)#
Delete a project instance.
- Parameters:
item
- Returns:
None
- classmethod delete_repository(item)#
Delete a repository instance.
- Parameters:
item
- Returns:
None
- classmethod get_astore(model)[source]#
Get the ASTORE for a model registered in the model repository.
- classmethod get_model(item, refresh=False)#
Return a model instance.
- Parameters:
- Returns:
RestObj or None – A dictionary containing the model attributes or None.
Notes
If item is a complete representation of the model it will be returned unless refresh is set. This prevents unnecessary REST calls when data is already available on the client.
- classmethod get_model_contents(model)[source]#
Retrieve the additional files and data associated with the model.
- classmethod get_model_details(model)[source]#
Get model details from SAS Model Manager
Get model details that pertain to model properties, model metadata, model input, output, and target variables, and user-defined values.
- classmethod get_model_link(model, rel, refresh=False)[source]#
Retrieve a link from a model’s set of links.
- Parameters:
- Returns:
dict or None – Dictionary containing the link’s properties
- classmethod get_project(item, refresh=False)#
Return a project instance.
- Parameters:
- Returns:
RestObj or None – A dictionary containing the project attributes or None.
Notes
If item is a complete representation of the project it will be returned unless refresh is set. This prevents unnecessary REST calls when data is already available on the client.
- classmethod get_repository(repository, refresh=False)[source]#
Return a repository instance.
- Parameters:
- Returns:
RestObj or None – A dictionary containing the repository attributes or None.
Notes
If repository is a complete representation of the repository it will be returned unless refresh is set. This prevents unnecessary REST calls when data is already available on the client.
- classmethod get_score_code(model)[source]#
Get the score code for a model registered in the model repository.
- classmethod import_model_from_zip(name, project, file, description=None, version='latest')[source]#
Import a model and contents as a ZIP file into a model project.
- Parameters:
project (str or dict) – The name or id of the model project, or a dictionary representation of the project.
file (bytes or file-like object) – The ZIP file containing the model and contents.
description (str) – The description of the model.
version (str, optional) – Name of the project version. Default value is “latest”.
- Returns:
RestObj – The API response after importing the model.
- classmethod list_model_versions(model)[source]#
Get a list of previous versions of a model.
The current model version is not included in the results.
- classmethod list_models(filter=None, start=None, limit=None, **kwargs)#
List all models available in the environment.
- Parameters:
- Returns:
list – A list of dictionaries containing the models.
Notes
See the filtering reference for details on the filter parameter.
- classmethod list_project_versions(project)[source]#
Get a list of all versions of a project.
- Parameters:
project (str or dict) – The name or id of the model project, or a dictionary representation of the model project.
- Returns:
list of dicts – List of dicts representing different project versions. Dict key/value pairs are as follows. - name : str - id : str - number : str - modified : datetime
- classmethod list_projects(filter=None, start=None, limit=None, **kwargs)#
List all projects available in the environment.
- Parameters:
- Returns:
list – A list of dictionaries containing the projects.
Notes
See the filtering reference for details on the filter parameter.