API Reference¶
ModelRegistryClient¶
- class kubeflow.hub.ModelRegistryClient(base_url: str, port: int | None = None, *, author: str | None = None, is_secure: bool | None = None, user_token: str | None = None, custom_ca: str | None = None)[source]¶
Bases:
objectClient for Kubeflow Model Registry operations.
Requires the model-registry package to be installed. Install it with:
pip install ‘kubeflow[hub]’
- __init__(base_url: str, port: int | None = None, *, author: str | None = None, is_secure: bool | None = None, user_token: str | None = None, custom_ca: str | None = None)[source]¶
Initialize the ModelRegistryClient.
- Parameters:
base_url (
str) – Base URL of the model registry server including scheme. Examples: “https://registry.example.com”, “http://localhost” The scheme is used to infer is_secure and port if not explicitly provided.- Keyword Arguments:
port – Server port. If not provided, inferred from base_url scheme: - https:// defaults to 443 - http:// defaults to 8080 - no scheme defaults to 443
author – Name of the author.
is_secure – Whether to use a secure connection. If not provided, inferred from base_url: - https:// sets is_secure=True - http:// sets is_secure=False - no scheme defaults to True
user_token – The PEM-encoded user token as a string.
custom_ca – Path to the PEM-encoded root certificates as a string.
- Raises:
ImportError – If model-registry is not installed.
Examples
ModelRegistryClient(”https://example.org”, port=456) # port kwarg ModelRegistryClient(”https://example.org:456”) # base_url (including port) ModelRegistryClient(”https://example.org”) # default port (443 for https, 8080 for http)
- register_model(name: str, uri: str, *, version: str, model_format_name: str | None = None, model_format_version: str | None = None, author: str | None = None, owner: str | None = None, version_description: str | None = None, metadata: Mapping[str, bool | int | float | str] | None = None, storage_config: StorageConfig | None = None) RegisteredModel[source]¶
Register a model.
This registers a model in the model registry. The model is not downloaded, and has to be stored prior to registration.
Most models can be registered using their URI, along with an optional storage_config describing how KServe should fetch the model at inference time. URI builder utilities are recommended when referring to specialized storage; for example utils.s3_uri_from when using S3 object storage data connections.
- Parameters:
- Keyword Arguments:
version – Version of the model. Has to be unique.
model_format_name – Name of the model format (e.g., “pytorch”, “tensorflow”, “onnx”). Used by KServe to select the appropriate serving runtime.
model_format_version – Version of the model format (e.g., “2.0”, “1.15”).
author – Author of the model. Defaults to the client author.
owner – Owner of the model. Defaults to the client author.
version_description – Description of the model version.
metadata – Additional version metadata.
storage_config – Storage credentials for the model artifact. Groups storage_key, storage_path, and service_account_name used by KServe’s StorageInitializer. See StorageConfig for details.
- Returns:
Registered model.
- update_model(model: RegisteredModel) RegisteredModel[source]¶
Update a registered model.
- Parameters:
model (
RegisteredModel) – The registered model to update. Must have an ID.- Returns:
Updated registered model.
- Raises:
TypeError – If model is not a RegisteredModel instance.
model_registry.exceptions.StoreError – If model does not have an ID.
- update_model_version(model_version: ModelVersion) ModelVersion[source]¶
Update a model version.
- Parameters:
model_version (
ModelVersion) – The model version to update. Must have an ID.- Returns:
Updated model version.
- Raises:
TypeError – If model_version is not a ModelVersion instance.
model_registry.exceptions.StoreError – If model version does not have an ID.
- update_model_artifact(model_artifact: ModelArtifact) ModelArtifact[source]¶
Update a model artifact.
- Parameters:
model_artifact (
ModelArtifact) – The model artifact to update. Must have an ID.- Returns:
Updated model artifact.
- Raises:
TypeError – If model_artifact is not a ModelArtifact instance.
model_registry.exceptions.StoreError – If model artifact does not have an ID.
- get_model(name: str) RegisteredModel[source]¶
Get a registered model.
- Parameters:
name (
str) – Name of the model.- Returns:
Registered model.
- Raises:
ValueError – If the model does not exist.
- get_model_version(name: str, version: str) ModelVersion[source]¶
Get a model version.
- Parameters:
- Returns:
Model version.
- Raises:
model_registry.exceptions.StoreError – If the model does not exist.
ValueError – If the version does not exist.
- get_model_artifact(name: str, version: str) ModelArtifact[source]¶
Get a model artifact.
- Parameters:
- Returns:
Model artifact.
- Raises:
model_registry.exceptions.StoreError – If either the model or the version don’t exist.
ValueError – If the artifact does not exist.
Types¶
The following types are returned by the client methods. They are provided by the
model-registry package.
- class model_registry.types.RegisteredModel(**data: Any) None[source]
Bases:
BaseResourceModelRepresents a registered model.
- name
Registered model name.
- owner
Owner of this Registered Model.
- description
Description of the object.
- external_id
Customizable ID. Has to be unique among instances of the same type.
- name: str
- state: RegisteredModelState
- create(**kwargs) RegisteredModelCreate[source]
Convert the object to a create request.
- update(**kwargs) RegisteredModelUpdate[source]
Convert the object to an update request.
- classmethod from_basemodel(source: RegisteredModel) RegisteredModel[source]
Create a new object from a BaseModel object.
- model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class model_registry.types.ModelVersion(**data: Any) None[source]
Bases:
BaseResourceModelRepresents a model version.
- name
Name of this version.
- author
Author of this model version.
- state
Status of this model version.
- description
Description of this object.
- external_id
Customizable ID. Has to be unique among instances of the same type.
- artifacts
Artifacts associated with this version.
- name: str
- state: ModelVersionState
- create(*, registered_model_id: str, **kwargs) ModelVersionCreate[source]
Convert the object to a create request.
- update(**kwargs) ModelVersionUpdate[source]
Convert the object to an update request.
- classmethod from_basemodel(source: ModelVersion) ModelVersion[source]
Create a new object from a BaseModel object.
- model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class model_registry.types.ModelArtifact(**data: Any) None[source]
Bases:
ArtifactRepresents a Model.
- name
Name of the model.
- uri
URI of the model.
- description
Description of the object.
- external_id
Customizable ID. Has to be unique among instances of the same type.
- model_format_name
Name of the model format.
- model_format_version
Version of the model format.
- storage_key
Storage secret name.
- storage_path
Storage path of the model.
- service_account_name
Name of the service account with storage secret.
- model_source_kind
A string identifier describing the source kind.
- model_source_class
A subgroup within the source kind.
- model_source_group
This identifies a source group for models from source class.
- model_source_id
A unique identifier for a source model within kind, class, and group.
- model_source_name
A human-readable name for the source model.
- create(**kwargs) ModelArtifactCreate[source]
Create a new ModelArtifactCreate object.
- update(**kwargs) ModelArtifactUpdate[source]
Create a new ModelArtifactUpdate object.
- as_basemodel() ModelArtifact[source]
Wrap the object in a BaseModel object.
- classmethod from_basemodel(source: ModelArtifact) ModelArtifact[source]
Create a new ModelArtifact object from a BaseModel object.
- model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self (
BaseModel) – The BaseModel instance.context (
Any) – The context.