Skip to content

Search external registry

This example demonstrates how you can use the MLOps Python client to search registered models of the external model registry using the ExternalRegisteredModelService of the MLOps API.

Before you begin

MLOPS_API_URL Usually: Defines the URL for the MLOps Gateway component.
TOKEN_ENDPOINT_URL https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token Defines the token endpoint URL of the Identity Provider. This uses Keycloak as the Identity Provider. Keycloak Realm should be provided.
REFRESH_TOKEN <your-refresh-token> Defines the user's refresh token.
CLIENT_ID <your-client-id> Sets the client id for authentication. This is the client you will be using to connect to MLOps.
CLIENT_SECRET <your-client-secret> Sets the client secret.
SEARCH_BY tag or name The API supports search by tag or name. To search models by tag, set the SEARCH_BY field as tag. To search by name, set it as name. Currently, only one clause at a time, either name or tag, is supported.
SEARCH_VALUE <key>=<value> or <name> If the SEARCH_BY field is tag, set the <key>=<value> pair of that tag here. This fetches any model that has the given <key>=<value> combination.

If the SEARCH_BY field is name, set the name of the search field here. This performs a LIKE %<FILTER_VALUE>% operation.


Using search criteria is optional. If the search criteria are not defined, the search will fetch all models in the external model registry, optimized by the default paging and sorting criteria.

The following steps demonstrate how you can use the MLOps Python client to search registered models of the external model registry.

  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>"
    SEARCH_BY = "tag" or "name"
    SEARCH_VALUE = "<key>=<value>" or "<name>"
  3. Run the file.

  4. This provides all the registered models in the external model registry that satisfy the search criteria you've specified. If no search criteria are specified, the search will fetch all models in the external model registry.

        "externalRegisteredModels" : [ {
            "sourceKey" : "sourceKey",
            "updatedTime" : "2000-01-23T04:56:07.000+00:00",
            "sourceCreatedBy" : "sourceCreatedBy",
            "createdBy" : "createdBy",
            "name" : "name",
            "description" : "description",
            "project" : {
            "displayName" : "displayName",
            "id" : "id",
            "ownerId" : "ownerId"
            "createdTime" : "2000-01-23T04:56:07.000+00:00",
            "id" : "id",
            "tags" : [ {
            "value" : "value",
            "key" : "key"
        "paging" : {
            "nextPageToken" : "nextPageToken"

Example walkthrough

This section provides a walkthrough of the file.

  1. Add the following function to filter the models.
    def _get_filter_by(type, value):
        return mlops.ModelregistryFilterRequest(
  2. Add the following function to sort the models.
    def _get_sort_by(field, order=mlops.ModelregistryOrder.DESCENDING):
        return mlops.ModelregistrySortingRequest(
  3. Search the models in the external model registry by calling the SearchRegisteredModel endpoint of the ExternalRegisteredModelService.
    def search_external_registry(
            mlops_client: mlops.Client, search_request: mlops.ModelregistrySearchRegisteredModelRequest
        return mlops_client.external_registry.external_registered_model_service.search_registered_model(search_request)
  4. In the main function, set up the token provider using an existing refresh token and client secret, and then set up the MLOps client.

  5. Call the search_external_registry function with the paging, filtering and sorting criteria.
    response = search_external_registry(mlops_client,  mlops.ModelregistrySearchRegisteredModelRequest(
                    paging = mlops.ModelregistryPagingRequest(),
                    filter = _get_filter_by(SEARCH_BY, SEARCH_VALUE),
                    sorting = _get_sort_by("lastUpdateTimestampMs")


    If no search criteria are defined at the beginning of the script, ensure that the filter = _get_filter_by(SEARCH_BY, SEARCH_VALUE) line is removed.