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.

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.

Parameters:

model (str or dict) – The name or id of the model, or a dictionary representation of the model.

Returns:

API response – JSON response detailing the API metadata

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.

Parameters:

model (str or dict) – The name, id, or dictionary representation of a model.

Returns:

RestObj

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.

Parameters:

model (str or dict) – The name or id of the model, or a dictionary representation of the model.

Returns:

RestObj or None – JSON response detailing the API metadata

Warns:

UserWarning – If no score resources exist for the model.

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:
  • model (str or dict) – The name, id, or dictionary representation of a model.

  • minor (bool, optional) – Whether the new version should be a minor version increment from the current version. Otherwise, a new major version will be created. Defaults to False.

Returns:

RestObj – The new version of the model.

classmethod create_project(project, repository, **kwargs)[source]#

Create a model project in the given model repository.

Parameters:
  • project (str or dict) – The name or id of the model project, or a dictionary representation of the project.

  • repository (str or dict) – The name or id of the model repository, or a dictionary representation of the repository.

Returns:

RestObj

classmethod default_repository()[source]#

Get the built-in default repository.

Returns:

RestObj

classmethod delete_model(item)#

Delete a model instance.

Parameters:

item

Returns:

None

classmethod delete_model_contents(model)[source]#

Deletes all contents (files) in the model.

Parameters:

model (str or dict) – The name, id, or dictionary representation of a model.

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.

Parameters:

model (str or dict) – The name or id of the model, or a dictionary representation of the model.

Returns:

BinaryIO

classmethod get_model(item, refresh=False)#

Return a model instance.

Parameters:
  • item (str or dict) – Name, ID, or dictionary representation of the model.

  • refresh (bool, optional) – Obtain an updated copy of the model.

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.

Parameters:

model (str or dict) – The name or id of the model, or a dictionary representation of the model.

Returns:

list – The code designated as the model’s score code

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.

Parameters:

model (str or dict) – The name or id of the model, or a dictionary representation of the model.

Returns:

API response – JSON response detailing the model details

Retrieve a link from a model’s set of links.

Parameters:
  • model (str or dict) – The name or id of the model, or a dictionary representation of the model.

  • rel (str) – The name of the link to retrieve

  • refresh (bool, optional) – Whether the model’s data should be refreshed before searching for the link.

Returns:

dict or None – Dictionary containing the link’s properties

classmethod get_project(item, refresh=False)#

Return a project instance.

Parameters:
  • item (str or dict) – Name, ID, or dictionary representation of the project.

  • refresh (bool, optional) – Obtain an updated copy of the project.

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:
  • repository (str or dict) – Name, ID, or dictionary representation of the repository.

  • refresh (bool, optional) – Obtain an updated copy of the repository.

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.

Parameters:

model (str or dict) – The name or id of the model, or a dictionary representation of the model.

Returns:

str – The code designated as the model’s score code

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:
  • name (str or dict) – The name of the model.

  • 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.

Parameters:

model (str or dict) – The name, id, or dictionary representation of a model.

Returns:

list

classmethod list_models(filter=None, start=None, limit=None, **kwargs)#

List all models available in the environment.

Parameters:
  • filter (str, optional)

  • start (int, optional) – Zero-based index of the first item to return. Defaults to 0.

  • limit (int, optional) – The maximum number of items to return. Defaults to 20.

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:
  • filter (str, optional)

  • start (int, optional) – Zero-based index of the first item to return. Defaults to 0.

  • limit (int, optional) – The maximum number of items to return. Defaults to 20.

Returns:

list – A list of dictionaries containing the projects.

Notes

See the filtering reference for details on the filter parameter.

classmethod list_repositories(filter=None, start=None, limit=None, **kwargs)#

List all repositories available in the environment.

Parameters:
  • filter (str, optional)

  • start (int, optional) – Zero-based index of the first item to return. Defaults to 0.

  • limit (int, optional) – The maximum number of items to return. Defaults to 20.

Returns:

list – A list of dictionaries containing the repositories.

Notes

See the filtering reference for details on the filter parameter.

classmethod update_model(item)#

Update a model instance.

Parameters:

item (dict)

Returns:

None

classmethod update_project(item)#

Update a project instance.

Parameters:

item (dict)

Returns:

None

classmethod update_repository(item)#

Update a repository instance.

Parameters:

item (dict)

Returns:

None