Discovery Service
The Discovery Service exposes the API end points that provide users with information about the platfrom environment and its particular components like API addresses and appropriate library versions. Users only need to know the URL of the H2O AI Cloud environment that they wish to connect to. By providing the URL, all additional information can be fetched automatically from the service.
It makes it easy for data scientists and app developers to easily access the information they need to interact with any component in the H2O AI Cloud for their app, Python projects, or Jupyter notebook.
Installation
h2o-cloud-discovery
is a Python library that is available on PyPI and can be installed using pip
.
pip install h2o-cloud-discovery
For more information about the package, see Discovery Service API documentation.
Discover products installed on HAIC
You can use the Discovery Service to find out information about the products or apps that are installed on your deployment of H2O AI Cloud.
- Locally
- Externally
Run the following commands to access the Discovery Service from within your H2O AI Cloud environment (locally) and list all the services that are installed on your environment.
export H2O_CLOUD_ENVIRONMENT="https://<your H2O AI Cloud domain >"
import h2o_discovery
discovery = h2o_discovery.discover()
for key, svc in discovery.services.items():
print(f"{key} ({svc.version})")
Run the following command to access the Discovery Service from outside your H2O AI Cloud environment and list all the services that are installed on your it.
import h2o_discovery
discovery = h2o_discovery.discover()
for key, svc in discovery.services.items():
print(f"{key} ({svc.version})")
The results may differ between local and in-environment execution as your environment may contain services that are available only internally. These "internal" services are not listed when the Discovery Service is accessed from outside of your environment.
Install the product Python libraries
You can use the Discovery Service to retrieve all the installed services on your HAIC environment and then download and install all the Python libraries relevant to those services, to your Python project. The sample code snippet shown below does this using the h2o_discovery
library.
This way, you will not have to spend time or effort trying to find out which versions of each product you have installed on your environment or which version of the library you need to install.
Locally
export H2O_CLOUD_ENVIRONMENT="https://<your H2O.ai Cloud domain>"
python <<EOF | pip install -r /dev/stdin
import h2o_discovery
discovery = h2o_discovery.discover()
for svc in h2o_discovery.discover().services.values():
if svc.python_client:
print(svc.python_client)
EOF
Some clients may not be available locally. Your environment may contain the services that are available only internally. These services are not listed when discovery is accessed from outside of the environment.
From within your notebook
# Cell 1
import h2o_discovery
discovery = h2o_discovery.discover()
# Cell 2
!{sys.executable} -m pip install '{discovery.services["drive"].python_client}'
Connect to H2O AI Cloud
Apps managed by H2O Cloud Appstore are set up so that there's no configuration
needed. Using the Discovery library you can automatically retrieve information like the platform token URL, platform client ID, and platform token endpoint when connecting to the H2O AI Cloud environment. This means that you can simply import the library and use the H2O_CLOUD_ENVIRONMENT
environment variable to retrieve the rest of the values instead of having to find and copy them over one by one.
The following code snippet provides an example of how to connect to the MLOps Python Client using the Discovery Service.
export H2O_CLOUD_ENVIRONMENT="https://<your H2O.ai Cloud domain>"
We recommend not to use the environment
argument of the discover
function
within the Wave App so that it can detect the environment automatically.
(unless you want to do explicit cross-environment calls).
import h2o_authn
import h2o_discovery
import h2o_mlops_client as mlops
from h2o_wave import Q, app
from h2o_wave import main
@app("/")
async def serve(q: Q):
# Wave App should use asynchronous variant of the discover function.
discovery = await h2o_discovery.discover_async()
token_provider = h2o_authn.AsyncTokenProvider(
refresh_token=q.auth.refresh_token,
issuer_url=discovery.environment.issuer_url,
# In the most of the cases clients need "platform" client.
client_id=discovery.clients["platform"].oauth2_client_id,
)
mlops_client = mlops.Client(
gateway_url=discovery.services["mlops-api"].uri,
token_provider=token_provider,
)
...
- Submit and view feedback for this page
- Send feedback about H2O AI Cloud | Docs to cloud-feedback@h2o.ai