Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.0.0 instead.
Reason given by maintainers: This release has breaking changes. It has been republished at 1.0.0. See: https://github.com/caraml-dev/universal-prediction-interface/releases/tag/v1.0.0

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

Metadata

Release files for caraml-upi-protos 0.3.7

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

Source distribution (sdist)

Source distribution for caraml-upi-protos 0.3.7
File Size Uploaded
caraml-upi-protos-0.3.7.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for caraml-upi-protos 0.3.7
File Interpreter ABI Platform
caraml_upi_protos-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 55.7 kB

Release files / caraml-upi-protos-0.3.7.tar.gz

Download URL caraml-upi-protos-0.3.7.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9dc67140daa4f488fff186324b23b93766084802469cb304835d10ffb4d55d01
BLAKE2b-256 checksum
How to use checksums
e6dadfa5a93661f4619065e06fb219b0d8670f5b2446e9c70e540bbf1e390823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release files / caraml_upi_protos-0.3.7-py3-none-any.whl

Download URL caraml_upi_protos-0.3.7-py3-none-any.whl
Size 37.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0574d9859ea24c98d24c305a060c3345d2387f90b42c5b1b870d614e2e72ab5
BLAKE2b-256 checksum
How to use checksums
7916c6aaf06b14dfcc3083fba2c4c031c7d15e77344af74d3651f9c106189a6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.3.7 This release

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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