Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

CaraML UPI Protos

Generated Python code from caraml-dev/universal-prediction-interface. The intent of this package is to ease creation of Python server / client compatible with CaraML dataplane.

Example Usage

Creating Server

  • Create server.py containing following dummy server code
from concurrent import futures

import grpc
import random
from caraml.upi.v1 import upi_pb2_grpc, upi_pb2, value_pb2
import caraml.upi.v1.upi_pb2 as upiv1

class Model(upi_pb2_grpc.UniversalPredictionServiceServicer):
    def PredictValues(self, request: upi_pb2.PredictValuesRequest, context: grpc.ServicerContext) -> upi_pb2.PredictValuesResponse:
        print(f"request: {request}")

        # Return random integer for each rows
        result_rows = []
        for row in request.prediction_rows:
            result_row = upi_pb2.PredictionResultRow(row_id=row.row_id, values=[value_pb2.NamedValue(name="result", type = value_pb2.NamedValue.INTEGER_VALUE_FIELD_NUMBER, integer_value=random.randint(0, 100))])
            result_rows.append(result_row)

        return upi_pb2.PredictValuesResponse(
            prediction_result_rows=result_rows,
        )

if __name__ == "__main__":
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    upi_pb2_grpc.add_UniversalPredictionServiceServicer_to_server(Model(), server)
    port = 9000
    print(f"Running upi server at port {port}")
    server.add_insecure_port(f"[::]:{port}")
    server.start()
    server.wait_for_termination()
  • Start the server
python server.py
> Running upi server at port 9000

Creating Client

  • Create client.py containing following client code
from caraml.upi.v1 import upi_pb2_grpc, upi_pb2
from caraml.upi.v1 import value_pb2
import grpc
import time

def run(server_port: 9000):
    with grpc.insecure_channel(f"localhost:{server_port}") as channel:
        stub = upi_pb2_grpc.UniversalPredictionServiceStub(channel)
        while True:
            response = stub.PredictValues(upi_pb2.PredictValuesRequest(
                prediction_rows=[
                    upi_pb2.PredictionRow(row_id="1", model_inputs=[
                    value_pb2.NamedValue(name="feature1", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=1.1),
                    value_pb2.NamedValue(name="feature2", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=2.2),
                    value_pb2.NamedValue(name="feature3", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=3.3),
                    value_pb2.NamedValue(name="feature4", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=4.4),
                    ]),
                    upi_pb2.PredictionRow(row_id="2", model_inputs=[
                    value_pb2.NamedValue(name="feature1", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=1.1),
                    value_pb2.NamedValue(name="feature2", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=2.2),
                    value_pb2.NamedValue(name="feature3", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=3.3),
                    value_pb2.NamedValue(name="feature4", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=4.4),
                    ]),
                    ]
            ))
            print(response)
            time.sleep(1)

if __name__ == "__main__":
    run(9000)
  • Start client in separate shell as the server
python client.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caraml-upi-protos-0.1.0rc2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caraml_upi_protos-0.1.0rc2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file caraml-upi-protos-0.1.0rc2.tar.gz.

File metadata

  • Download URL: caraml-upi-protos-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.13

File hashes

Hashes for caraml-upi-protos-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 f0c6567d9a7ef1f9027bc05eda521c9e84b13316e8f1c67931719fc7f49a23fb
MD5 e253f4de02a548869cecac98a0373bd8
BLAKE2b-256 238a93e06d44e7994e3f8d1f994e3b008a01fdef0b29292939cfb2cdf59b2470

See more details on using hashes here.

File details

Details for the file caraml_upi_protos-0.1.0rc2-py3-none-any.whl.

File metadata

File hashes

Hashes for caraml_upi_protos-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 c15c4344fdc604f6274344a8d630de9f226d194b3b15e0dc6328c4fb0d071923
MD5 1d8e5ceaea6c93ebec8823ea6c191a0c
BLAKE2b-256 1dd767069c5df7d351812bb3dd380b963b4ed0716fd11298b03da3c225c8d088

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page