Hopsworks Python SDK

4.8.1 · active · verified Fri Apr 17

The Hopsworks Python SDK provides a client library to interact with the Hopsworks Platform, including its Feature Store, Model Registry, and Model Serving capabilities. It allows data scientists and ML engineers to programmatically manage ML artifacts and data. The library is actively maintained, with frequent minor releases (often monthly or bi-monthly) to introduce new features and improvements. The current version is 4.8.1.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a Hopsworks instance, retrieve a project, and access its Feature Store using environment variables for sensitive credentials. It includes error handling for common connection issues and accessing a non-existent feature group.

import os
import hopsworks

# Configuration from environment variables for security and flexibility
HOPSWORKS_HOST = os.environ.get("HOPSWORKS_HOST", "https://your_hopsworks_instance.com")
HOPSWORKS_API_KEY = os.environ.get("HOPSWORKS_API_KEY", "")

if not HOPSWORKS_API_KEY:
    print("Warning: HOPSWORKS_API_KEY environment variable not set. Login might fail or prompt for input.")

try:
    # Connect to Hopsworks
    # If running inside a Hopsworks environment (e.g., a notebook), no arguments are typically needed.
    # For external connections, host and api_key_value are required.
    project = hopsworks.login(host=HOPSWORKS_HOST, api_key_value=HOPSWORKS_API_KEY)
    print(f"Successfully connected to Hopsworks project: {project.name}")

    # Access the Feature Store
    fs = project.get_feature_store()
    print(f"Accessed Feature Store: {fs.name}")

    # Example: Get a feature group (replace with an existing one or create a new one)
    try:
        fg = fs.get_feature_group("example_feature_group", version=1)
        print(f"Retrieved feature group: {fg.name}")
    except Exception as e:
        print(f"Could not retrieve feature group 'example_feature_group': {e}. "
              "Please ensure it exists or create one.")

except Exception as e:
    print(f"Failed to connect to Hopsworks: {e}")
    print("Please check your HOPSWORKS_HOST and HOPSWORKS_API_KEY.")

view raw JSON →