From 3fb312cf25fb630745fe4d2b431f493f6a98f784 Mon Sep 17 00:00:00 2001 From: Robin Andersson Date: Fri, 10 May 2024 15:55:03 +0200 Subject: [PATCH] fix --- python/hopsworks/__init__.py | 50 +++++++++++++++++++----------------- python/hopsworks/project.py | 29 ++++++++++++++++++++- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/python/hopsworks/__init__.py b/python/hopsworks/__init__.py index 4d62bc3fa..286bfe329 100644 --- a/python/hopsworks/__init__.py +++ b/python/hopsworks/__init__.py @@ -72,21 +72,27 @@ def login( ) -> project.Project: """Connect to [Serverless Hopsworks](https://app.hopsworks.ai) by calling the `hopsworks.login()` function with no arguments. - ```python + !!! example "Connect to Serverless" + ```python - project = hopsworks.login() + import hopsworks - ``` + project = hopsworks.login() + + ``` Alternatively, connect to your own Hopsworks installation by specifying the host, port and api key. - ```python + !!! example "Connect to your Hopsworks cluster" + ```python + + import hopsworks - project = hopsworks.login(host="my.hopsworks.server", - port=8181, - api_key_value="DKN8DndwaAjdf98FFNSxwdVKx") + project = hopsworks.login(host="my.hopsworks.server", + port=8181, + api_key_value="DKN8DndwaAjdf98FFNSxwdVKx") - ``` + ``` In addition to setting function arguments directly, `hopsworks.login()` also reads the environment variables: HOPSWORKS_HOST, HOPSWORKS_PORT, HOPSWORKS_PROJECT and HOPSWORKS_API_KEY. @@ -327,17 +333,16 @@ def _is_connection_active(): def get_current_project() -> project.Project: """Get a reference to the current logged in project. - Example for creating a new project + !!! example "Example for getting the project reference" + ```python - ```python + import hopsworks - import hopsworks + hopsworks.login() - hopsworks.login() + project = hopsworks.get_current_project() - project = hopsworks.get_current_project() - - ``` + ``` # Returns `Project`. The Project object to perform operations on @@ -358,20 +363,19 @@ def _initialize_module_apis(): def create_project(name: str, description: str = None, feature_store_topic: str = None): """Create a new project. - !!! warn + !!! warning "Not supported" This is not supported if you are connected to [Serverless Hopsworks](https://app.hopsworks.ai) - Example for creating a new project - - ```python + !!! example "Example for creating a new project" + ```python - import hopsworks + import hopsworks - hopsworks.login() + hopsworks.login(...) - hopsworks.create_project("my_hopsworks_project", description="An example Hopsworks project") + hopsworks.create_project("my_project", description="An example Hopsworks project") - ``` + ``` # Arguments name: The name of the project. description: optional description of the project diff --git a/python/hopsworks/project.py b/python/hopsworks/project.py index a2cdcd727..c53d602ff 100644 --- a/python/hopsworks/project.py +++ b/python/hopsworks/project.py @@ -109,10 +109,19 @@ def get_feature_store(self, name: str = None, engine: str = None) -> feature_sto Defaulting to the project name of default feature store. To get a shared feature store, the project name of the feature store is required. + !!! example "Example for getting the Feature Store API of a project" + ```python + import hopsworks + + project = hopsworks.login() + + fs = project.get_feature_store() + ``` + # Arguments name: Project name of the feature store. engine: Which engine to use, `"spark"`, `"python"` or `"training"`. - Defaults to `"python"` when connected to https://c.app.hopsworks.ai/. + Defaults to `"python"` when connected to [Serverless Hopsworks](https://app.hopsworks.ai). See hsfs.Connection.connection documentation for more information. # Returns `hsfs.feature_store.FeatureStore`: The Feature Store API @@ -138,6 +147,15 @@ def get_feature_store(self, name: str = None, engine: str = None) -> feature_sto def get_model_registry(self): """Connect to Project's Model Registry API. + !!! example "Example for getting the Model Registry API of a project" + ```python + import hopsworks + + project = hopsworks.login() + + mr = project.get_model_registry() + ``` + # Returns `hsml.model_registry.ModelRegistry`: The Model Registry API # Raises @@ -159,6 +177,15 @@ def get_model_registry(self): def get_model_serving(self): """Connect to Project's Model Serving API. + !!! example "Example for getting the Model Serving API of a project" + ```python + import hopsworks + + project = hopsworks.login() + + ms = project.get_model_serving() + ``` + # Returns `hsml.model_serving.ModelServing`: The Model Serving API # Raises