Skip to main content

An H2O MLOps Python Client

Example

import h2o_mlops
import h2o_mlops.options as options
import h2o_mlops.types as types

First, we need to connect to MLOps. In the default case, the client detects credentials and configuration options from the environment.

mlops = h2o_mlops.Client()

Alternatively, you can initialize the client explicitly by passing the required parameters.

mlops = h2o_mlops.Client(
    h2o_cloud_url=<H2O_CLOUD_URL>,
    refresh_token=<REFRESH_TOKEN>,
    ssl_cacert="/path/to/your/ca_certificate.pem",  # If SSL is not needed, you can omit it.
)

Replace <H2O_CLOUD_URL> and <REFRESH_TOKEN> with your actual values.

Everything Starts with a Workspace

A workspace is the main base of operations for most MLOps activities.

workspace = mlops.workspaces.create(name="demo")
mlops.workspaces.list(name="demo")
    | name   | uid
----+--------+--------------------------------------
  0 | demo   | 45e5a888-ec1f-4f9c-85ca-817465344b1f

You can also do workspace = mlops.workspaces.get(uid=...).

Upload an Experiment

experiment = workspace.experiments.create(
    data="/path/to/your/model.zip",
    name="experiment-from-client"
)

Some experiment attributes of interest.

experiment.uid
'e307aa9f-895f-4b07-9404-b0728d1b7f03'

Existing experiments can be viewed and retrieved.

workspace.experiments.list()
    | name                   | uid                                  | tags
----+------------------------+--------------------------------------+--------
  0 | experiment-from-client | e307aa9f-895f-4b07-9404-b0728d1b7f03 |

You can also do experiment = workspaces.experiments.get(uid=...).

Create a Model

model = workspace.models.create(name="model-from-client")

Existing models can be viewed and retrieved.

workspace.models.list()
    | name              | uid
----+-------------------+--------------------------------------
  0 | model-from-client | d18a677f-b800-4a4b-8642-0f59e202d225

You can also do model = workspaces.models.get(uid=...).

Register an Experiment to a Model

In order to deploy a model, it needs to have experiments registered to it.

model.register(experiment=experiment)
model.versions()
    |   version | experiment_uid
----+-----------+--------------------------------------
  0 |         1 | e307aa9f-895f-4b07-9404-b0728d1b7f03
model.experiment(model_version="latest").name
'experiment-from-client'

Deployment

What is needed for a single model deployment?

  • workspace
  • model
  • scoring runtime
  • security options
  • name for deployment

We already have a workspace and model. Next we'll get the scoring_runtime for our model type, from the scoring runtime suggestions for the experiment to select the appropriate one.

model.experiment().scoring_runtimes
    | name              | artifact_type   | uid
----+-------------------+-----------------+-------------------
  0 | H2O-3 MOJO scorer | h2o3_mojo       | h2o3_mojo_runtime
scoring_runtime = model.experiment().scoring_runtimes[0]

Now we can create a deployment.

deployment = workspace.deployments.create(
    name="deployment-from-client",
    composition_options=options.CompositionOptions(
        model=model,
        scoring_runtime=scoring_runtime,
    ),
    security_options=options.SecurityOptions(
        security_type=types.SecurityType.DISABLED,
    ),
)

deployment.wait_for_healthy()
    
deployment.state
'HEALTHY'

Score

Once you have a deployment, you can score with it through the HTTP protocol.

scorer = deployment.scorer

scorer.score(
    payload=scorer.sample_request(auth_value=...),
    auth_value=...,
)
{'fields': ['C11.0', 'C11.1'],
 'id': 'e307aa9f-895f-4b07-9404-b0728d1b7f03',
 'score': [['0.49786656666743145', '0.5021334333325685']]}

Metadata

Release files for h2o-mlops 1.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for h2o-mlops 1.6.2
File Interpreter ABI Platform
h2o_mlops-1.6.2-py3-none-any.whl Python 3 none any Details

Release files / h2o_mlops-1.6.2-py3-none-any.whl

Download URL h2o_mlops-1.6.2-py3-none-any.whl
Size 264.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fec7d5af6afaeb356e2b8859164b1fd87402724aa14fcdfd2ad77f74cf1c97d
BLAKE2b-256 checksum
How to use checksums
5938612a20922f9afe7c9919739320b010619fb7150a5a5b32c93dae666b5d57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.6.4

1 release file

1.6.3

1 release file

This release

1.6.2 This release

1 release file

1.6.1

1 release file

1.6.0

1 release file

1.5.3

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.12

1 release file

1.4.11

1 release file

1.4.10

1 release file

1.4.9

1 release file

1.4.8

1 release file

1.4.7

1 release file

1.4.6

1 release file

1.4.5

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page