Name | caraml-upi-protos JSON |
Version |
1.0.0
JSON |
| download |
home_page | |
Summary | Generated Python code from caraml-dev/universal-prediction-interface |
upload_time | 2023-11-08 23:14:20 |
maintainer | |
docs_url | None |
author | CaraML Developer |
requires_python | >=3.7 |
license | |
keywords |
caraml
upi
grpc
protobuf
stub
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# CaraML UPI Protos
Generated Python code from [caraml-dev/universal-prediction-interface](https://github.com/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
```python
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
```bash
python server.py
> Running upi server at port 9000
```
#### Creating Client
- Create `client.py` containing following client code
```python
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
```bash
python client.py
```
Raw data
{
"_id": null,
"home_page": "",
"name": "caraml-upi-protos",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "caraml,upi,grpc,protobuf,stub",
"author": "CaraML Developer",
"author_email": "dsp@gojek.com",
"download_url": "https://files.pythonhosted.org/packages/14/3d/84dd2069b6d86464b90a1e55b7118fc3ff142e7abb483abcfdd8e1c885cc/caraml-upi-protos-1.0.0.tar.gz",
"platform": null,
"description": "# CaraML UPI Protos\n\nGenerated Python code from [caraml-dev/universal-prediction-interface](https://github.com/caraml-dev/universal-prediction-interface). \nThe intent of this package is to ease creation of Python server / client compatible with CaraML dataplane.\n\n## Example Usage\n\n#### Creating Server\n\n- Create `server.py` containing following dummy server code \n\n```python\nfrom concurrent import futures\n\nimport grpc\nimport random\nfrom caraml.upi.v1 import upi_pb2_grpc, upi_pb2, value_pb2\nimport caraml.upi.v1.upi_pb2 as upiv1\n\nclass Model(upi_pb2_grpc.UniversalPredictionServiceServicer):\n def PredictValues(self, request: upi_pb2.PredictValuesRequest, context: grpc.ServicerContext) -> upi_pb2.PredictValuesResponse:\n print(f\"request: {request}\")\n\n # Return random integer for each rows\n result_rows = []\n for row in request.prediction_rows:\n 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))])\n result_rows.append(result_row)\n\n return upi_pb2.PredictValuesResponse(\n prediction_result_rows=result_rows,\n )\n\nif __name__ == \"__main__\":\n server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))\n upi_pb2_grpc.add_UniversalPredictionServiceServicer_to_server(Model(), server)\n port = 9000\n print(f\"Running upi server at port {port}\")\n server.add_insecure_port(f\"[::]:{port}\")\n server.start()\n server.wait_for_termination()\n```\n\n- Start the server\n\n```bash\npython server.py\n> Running upi server at port 9000\n```\n\n#### Creating Client\n\n- Create `client.py` containing following client code\n\n```python\nfrom caraml.upi.v1 import upi_pb2_grpc, upi_pb2\nfrom caraml.upi.v1 import value_pb2\nimport grpc\nimport time\n\ndef run(server_port: 9000):\n with grpc.insecure_channel(f\"localhost:{server_port}\") as channel:\n stub = upi_pb2_grpc.UniversalPredictionServiceStub(channel)\n while True:\n response = stub.PredictValues(upi_pb2.PredictValuesRequest(\n prediction_rows=[\n upi_pb2.PredictionRow(row_id=\"1\", model_inputs=[\n value_pb2.NamedValue(name=\"feature1\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=1.1),\n value_pb2.NamedValue(name=\"feature2\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=2.2),\n value_pb2.NamedValue(name=\"feature3\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=3.3),\n value_pb2.NamedValue(name=\"feature4\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=4.4),\n ]),\n upi_pb2.PredictionRow(row_id=\"2\", model_inputs=[\n value_pb2.NamedValue(name=\"feature1\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=1.1),\n value_pb2.NamedValue(name=\"feature2\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=2.2),\n value_pb2.NamedValue(name=\"feature3\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=3.3),\n value_pb2.NamedValue(name=\"feature4\", type=value_pb2.NamedValue.DOUBLE_VALUE_FIELD_NUMBER, double_value=4.4),\n ]),\n ]\n ))\n print(response)\n time.sleep(1)\n\nif __name__ == \"__main__\":\n run(9000)\n```\n\n- Start client in separate shell as the server\n\n```bash\npython client.py\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Generated Python code from caraml-dev/universal-prediction-interface",
"version": "1.0.0",
"project_urls": null,
"split_keywords": [
"caraml",
"upi",
"grpc",
"protobuf",
"stub"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3650dc0a942d48effa2de08c28e82e3426ff5b9141527620f0ecc8197f625349",
"md5": "d7bf05d2741d3e21fd7f40d93decc79d",
"sha256": "540489791683aa4db174f4eb298f02e17a2b2250fb930077f39b6dc78df8a677"
},
"downloads": -1,
"filename": "caraml_upi_protos-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d7bf05d2741d3e21fd7f40d93decc79d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 37948,
"upload_time": "2023-11-08T23:14:18",
"upload_time_iso_8601": "2023-11-08T23:14:18.485092Z",
"url": "https://files.pythonhosted.org/packages/36/50/dc0a942d48effa2de08c28e82e3426ff5b9141527620f0ecc8197f625349/caraml_upi_protos-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "143d84dd2069b6d86464b90a1e55b7118fc3ff142e7abb483abcfdd8e1c885cc",
"md5": "b657cba7366b3a3435e9d6e433830855",
"sha256": "ae9a742c872eedd51caedc5579e2722968e980e0b23ebb66e594cd7ad3473dc1"
},
"downloads": -1,
"filename": "caraml-upi-protos-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "b657cba7366b3a3435e9d6e433830855",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 17762,
"upload_time": "2023-11-08T23:14:20",
"upload_time_iso_8601": "2023-11-08T23:14:20.148384Z",
"url": "https://files.pythonhosted.org/packages/14/3d/84dd2069b6d86464b90a1e55b7118fc3ff142e7abb483abcfdd8e1c885cc/caraml-upi-protos-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-08 23:14:20",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "caraml-upi-protos"
}