Connecting to the Model Registry from any Python environment requires setting up a Model Registry API key and installing the library. This guide explains step by step how to connect to the Model Registry from any Python environment such as your local environment.
Generate an API key#
In Hopsworks, click on your username in the top-right corner and select Settings to open the user settings. Select API keys. Give the key a name and select the project, modelregistry, dataset.create, dataset.view, dataset.delete scopes before creating the key. Copy the key into your clipboard. More documentation can be found here.
Create a file called
modelregistry.key in your designated Python environment and save the API key from your clipboard in the file.
The API key should contain at least the following scopes:
You are only able to retrieve the API key once. If you did not manage to copy it to your clipboard, delete it and create a new one.
To be able to access the Hopsworks Model Registry, the
HSML Python library needs to be installed in the environment from which you want to connect to the Model Registry. You can install the library through pip. We recommend using a Python environment manager such as virtualenv or conda.
Matching Hopsworks version
The major and minor version of
HSML needs to match the major and minor version of Hopsworks.
For example for a Hopsworks cluster running with version 2.5.0, the following installation command will install the latest release available for HSML.
pip install hsml==2.5.*
Connect to the Model Registry#
You are now ready to connect to the Hopsworks Model Registry from your Python environment:
import hsml conn = hsml.connection( host='my_instance', # DNS of your Model Registry instance port=443, # Port to reach your Hopsworks instance, defaults to 443 project='my_project', # Name of your Hopsworks Model Registry project api_key_value='apikey', # The API key to authenticate with Hopsworks hostname_verification=True # Disable for self-signed certificates ) mr = conn.get_model_registry() # Get the project's default model registry
If you are unable to connect, please ensure that your Model Registry can receive incoming traffic from your Python environment on port 443.
For more information about how to connect, see the Connection guide.