Connection#
Connection#
hsml.connection.Connection(
host=None,
port=443,
project=None,
hostname_verification=True,
trust_store_path=None,
api_key_file=None,
api_key_value=None,
)
A Hopsworks Model Management connection object.
The connection is project specific, so you can access the project's own Model Registry and Model Serving.
This class provides convenience classmethods accessible from the hsml
-module:
Connection factory
For convenience, hsml
provides a factory method, accessible from the top level
module, so you don't have to import the Connection
class manually:
import hsml
conn = hsml.connection()
Save API Key as File
To get started quickly, you can simply create a file with the previously created Hopsworks API Key and place it on the environment from which you wish to connect to Hopsworks.
You can then connect by simply passing the path to the key file when instantiating a connection:
import hsml
conn = hsml.connection(
'my_instance', # DNS of your Hopsworks instance
443, # Port to reach your Hopsworks instance, defaults to 443
'my_project', # Name of your Hopsworks project
api_key_file='modelregistry.key', # The file containing the API key generated above
hostname_verification=True) # Disable for self-signed certificates
)
mr = conn.get_model_registry() # Get the project's default model registry
ms = conn.get_model_serving() # Uses the previous model registry
Clients in external clusters need to connect to the Hopsworks Model Registry and Model Serving using an API key. The API key is generated inside the Hopsworks platform, and requires at least the "project", "modelregistry", "dataset.create", "dataset.view", "dataset.delete", "serving" and "kafka" scopes to be able to access a model registry and its model serving. For more information, see the integration guides.
Arguments
- host
Optional[str]
: The hostname of the Hopsworks instance, defaults toNone
. - port
int
: The port on which the Hopsworks instance can be reached, defaults to443
. - project
Optional[str]
: The name of the project to connect to. When running on Hopsworks, this defaults to the project from where the client is run from. Defaults toNone
. - hostname_verification
bool
: Whether or not to verify Hopsworks certificate, defaults toTrue
. - trust_store_path
Optional[str]
: Path on the file system containing the Hopsworks certificates, defaults toNone
. - api_key_file
Optional[str]
: Path to a file containing the API Key. - api_key_value
Optional[str]
: API Key as string, if provided, however, this should be used with care, especially if the used notebook or job script is accessible by multiple parties. Defaults toNone
.
Returns
Connection
. Connection handle to perform operations on a Hopsworks project.
Properties#
api_key_file#
api_key_value#
host#
hostname_verification#
port#
project#
Methods#
close#
Connection.close()
Close a connection gracefully.
This will clean up any materialized certificates on the local file system of external environments.
Usage is recommended but optional.
connect#
Connection.connect()
Instantiate the connection.
Creating a Connection
object implicitly calls this method for you to
instantiate the connection. However, it is possible to close the connection
gracefully with the close()
method, in order to clean up materialized
certificates. This might be desired when working on external environments.
Subsequently you can call connect()
again to reopen the connection.
Example
import hsml
conn = hsml.connection()
conn.close()
conn.connect()
connection#
Connection.connection(
host=None,
port=443,
project=None,
hostname_verification=True,
trust_store_path=None,
api_key_file=None,
api_key_value=None,
)
Connection factory method, accessible through hsml.connection()
.
get_model_registry#
Connection.get_model_registry(project=None)
Get a reference to a model registry to perform operations on, defaulting to the project's default model registry.
Shared model registries can be retrieved by passing the project
argument.
Arguments
- project
str
: The name of the project that owns the shared model registry, the model registry must be shared with the project the connection was established for, defaults toNone
.
Returns
ModelRegistry
. A model registry handle object to perform operations on.
get_model_serving#
Connection.get_model_serving()
Get a reference to model serving to perform operations on. Model serving operates on top of a model registry, defaulting to the project's default model registry.
Returns
ModelServing
. A model serving handle object to perform operations on.