hydrosdk.application module

class hydrosdk.application.Application(cluster, id, name, execution_graph, status, signature, kafka_streaming, metadata=None, message=None)

Bases: object

Applications are used to combine your ModelVersions into a linear graph and deploy it into production, exposing HTTP and gRPC interfaces for consumers.

Use ApplicationBuilder class to create a new Application in your Hydrosphere cluster or an Application.find method to get the existing Application.

Example

Parameters
Return type

Application

List all applications created on the cluster.

>>> from hydrosdk.cluster import Cluster
>>> cluster = Cluster("http-cluster-endpoint")
>>> apps = Application.list(cluster)
>>> for app in apps:
>>>     print(app)

Find an application by name and perform a prediction from it.

>>> from hydrosdk.cluster import Cluster
>>> cluster = Cluster("http-cluster-endpoint", "grpc-cluster-endpoint")  # important to use a gRPC endpoint
>>> app = Application.find(cluster, "my-application")
>>> pred = app.predictor()
>>> resp = pred.predict({"my-input": 1})
Parameters
  • cluster (hydrosdk.cluster.Cluster) – active cluster

  • id (int) – unique application ID

  • name (str) – application Name

  • signature (hydro_serving_grpc.serving.contract.signature_pb2.ModelSignature) – signature, specifying input and output fields names, dtypes and shapes

  • execution_graph (ExecutionGraph) – linear graph which specifies ExecutionStages which sequentially transform input

  • status (hydrosdk.application.ApplicationStatus) – Application Status

  • kafka_streaming (List[hydrosdk.application.StreamingParams]) – list of Kafka parameters with input and output Kafka topics specified

  • metadata (Optional[Dict[str, str]]) – metadata with string keys and string values.

  • message (Optional[str]) – possible error message from the cluster

Return type

Application

static delete(cluster, application_name)

Delete an application by name.

Parameters
Returns

response from the cluster

Return type

dict

static find(cluster, application_name)

Search for an application by name.

Parameters
Returns

deserialized application object

Return type

hydrosdk.application.Application

static list(cluster)

List all available applications from the cluster.

Parameters

cluster (hydrosdk.cluster.Cluster) – active cluster

Returns

deserialized list of application objects

Return type

List[hydrosdk.application.Application]

lock_while_starting(timeout=120)

Wait for an application to become ready.

Parameters

timeout (int) –

Return type

hydrosdk.application.Application

predictor(return_type=PredictorDT.DICT_NP_ARRAY)

Return a predictor object which is used to transform your data into a proto message, pass it via gRPC to the cluster and decode the cluster output from proto to a dict with Python dtypes.

Parameters

return_type – Specifies into which format should predictor serialize model output. Numpy dtypes, Python dtypes or pd.DataFrame are supported.

Returns

PredictServiceClient with .predict() method which accepts your data

Return type

hydrosdk.predictor.PredictServiceClient

class hydrosdk.application.ApplicationBuilder(name)

Bases: object

ApplicationBuilder is used to create new Applications in your cluster.

Example

Parameters

name (str) –

Return type

ApplicationBuilder

Create an application from existing modelversions.

>>> from hydrosdk import Cluster, ModelVersion
>>> cluster = Cluster('http-cluster-endpoint')
>>> mv1 = ModelVersion.find(cluster, "my-model", 1)
>>> mv2 = ModelVersion.find(cluster, "my-model", 2)
>>> stage = ExecutionStageBuilder()                     .with_model_variant(mv1, 50)                     .with_model_variant(mv2, 50) \
                .build()
>>> app = ApplicationBuilder("my-application-ab-test")                 .with_stage(stage)                 .build(cluster)
Parameters
  • cluster – Hydrosphere cluster where you want to create an Application

  • name (str) – Future Application name

Return type

ApplicationBuilder

build(cluster)

Create an Application in your Hydrosphere cluster.

Returns

Application object

Parameters

cluster (hydrosdk.cluster.Cluster) –

Return type

hydrosdk.application.Application

with_kafka_params(source_topic, dest_topic)

Add a kafka parameters to your Application.

Parameters
  • source_topic (str) – source Kafka topic

  • dest_topic (str) – destination Kafka topic

Returns

Return type

hydrosdk.application.ApplicationBuilder

with_metadata(key, value)

Add a metadata value to your future Application.

Parameters
  • key (str) – string key under which value will be stored

  • value (str) – string value

Returns

Return type

hydrosdk.application.ApplicationBuilder

with_metadatas(metadata)

Add a metadata to your future Application.

Parameters

metadata (Dict[str, str]) – a dict containing metadata for your application

Returns

Return type

hydrosdk.application.ApplicationBuilder

with_stage(stage)

Add an ExecutionStage to your Application. See ExecutionStage for more information.

Parameters

stage (hydrosdk.application.ExecutionStage) –

Returns

Return type

hydrosdk.application.ApplicationBuilder

class hydrosdk.application.ApplicationStatus(value)

Bases: enum.Enum

An enumeration.