Skip to content

Count registered models

This example demonstrates how you can use the MLOps Python client to count the number of registered models for a given project id using the RegisteredModelService of the MLOps API.

Before you begin

You will need the values for the following constants in order to successfully carry out the task. Contact your administrator to obtain deployment specific values.

MLOPS_API_URL Defines the URL for the MLOps gateway component. Usually:
TOKEN_ENDPOINT_URL Defines the token endpoint URL of the identity provider. This uses Keycloak as the identity provider. Keycloak realm should be provided.
REFRESH_TOKEN Defines the user's refresh token.
CLIENT_ID Sets the client id for authentication. This is the client you will be using to connect to MLOps.
CLIENT_SECRET Sets the client secret for authentication.
PROJECT_ID Sets the project id.

The following steps demonstrate how you can use the MLOps Python client to to count the number of registered models for a given project in MLOps.

  1. Download the file.

  2. Change the values of the following constants in your file as given in the preceding data table.
    ### Constants
    MLOPS_API_URL = ""
    CLIENT_SECRET = "<your-client-secret>"
    PROJECT_ID = "<your-project-id>"
  3. Run the file.

  4. This provides the number of registered models in the project you have specified.

        "registeredModelCount" : 3

Example walkthrough

This section provides a walkthrough of the file.

  1. Count the number of registered models for a given project id by calling the CreateModelVersion endpoint of the RegisteredModelVersionService. The request for this API call is prepared by the get_count_registered_model_request function, which specifies the project id.
    def count_registered_models(
            mlops_client: mlops.Client, 
            count_model_request: mlops.StorageCountRegisteredModelRequest
    def get_count_registered_model_request(project_id):
        return mlops.StorageCountRegisteredModelRequest(
  2. In the main function, set up the token provider using an existing refresh token and client secret, and then set up the MLOps client.

  3. Call the count_registered_models function with the PROJECT_ID constant defined in the beginning of the script.
    count_model_response: mlops.StorageCountRegisteredModelResponse = count_registered_models(