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
cluster (hydrosdk.cluster.Cluster) –
id (int) –
name (str) –
execution_graph (ExecutionGraph) –
status (hydrosdk.application.ApplicationStatus) –
signature (hydro_serving_grpc.serving.contract.signature_pb2.ModelSignature) –
kafka_streaming (List[hydrosdk.application.StreamingParams]) –
message (Optional[str]) –
- Return type
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
- static delete(cluster, application_name)¶
Delete an application by name.
- Parameters
cluster (hydrosdk.cluster.Cluster) – active cluster
application_name (str) – application name
- Returns
response from the cluster
- Return type
- static find(cluster, application_name)¶
Search for an application by name.
- Parameters
cluster (hydrosdk.cluster.Cluster) – active cluster
application_name (str) – application name
- Returns
deserialized application object
- Return type
- 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
- lock_while_starting(timeout=120)¶
Wait for an application to become ready.
- Parameters
timeout (int) –
- Return type
- 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
- class hydrosdk.application.ApplicationBuilder(name)¶
Bases:
object
ApplicationBuilder is used to create new Applications in your cluster.
- Example
- Parameters
name (str) –
- Return type
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
- build(cluster)¶
Create an Application in your Hydrosphere cluster.
- Returns
Application object
- Parameters
cluster (hydrosdk.cluster.Cluster) –
- Return type
- with_kafka_params(source_topic, dest_topic)¶
Add a kafka parameters to your Application.
- Parameters
- Returns
- Return type
- with_metadata(key, value)¶
Add a metadata value to your future Application.
- Parameters
- Returns
- Return type
- with_metadatas(metadata)¶
Add a metadata to your future Application.
- with_stage(stage)¶
Add an ExecutionStage to your Application. See ExecutionStage for more information.
- Parameters
stage (hydrosdk.application.ExecutionStage) –
- Returns
- Return type