Open Inference Protocol gRPC Client
open-inference-grpc is a generated client library based on the gRPC protocol definition tracked in the open-inference/open-inference-protocol/ repository.
Installation
This package requires Python 3.8 or greater.
Install with your favorite tool from pypi.org/project/open-inference-grpc/
$ pip install open-inference-grpc
$ poetry add open-inference-grpc
A REST-based python client (
open-inference-openapi) also exists for the Open Inference Protocol, and can be installed alongside this gRPC client, as both are distributed as namespace packages.
Example
# These dependencies are installed by open-inference-grpc
import grpc
from google.protobuf.json_format import MessageToDict
from open_inference.grpc.service import GRPCInferenceServiceStub
from open_inference.grpc.protocol import (
ServerReadyRequest,
ModelReadyRequest,
ModelMetadataRequest,
ModelInferRequest,
)
with grpc.insecure_channel("localhost:8081") as channel:
client = GRPCInferenceServiceStub(channel)
# Check that the server is live, and it has the iris model loaded
client.ServerReady(ServerReadyRequest())
client.ModelReady(ModelReadyRequest(name="iris-model"))
# Make an inference request
pred = client.ModelInfer(
ModelInferRequest(
model_name="iris-model",
inputs=[
{
"name": "input-0",
"datatype": "FP64",
"shape": [1, 4],
"contents": {"fp64_contents": [5.3, 3.7, 1.5, 0.2]},
}
],
)
)
print(MessageToDict(pred))
# {
# "modelName": "iris-model",
# "parameters": {"content_type": {"stringParam": "np"}},
# "outputs": [
# {
# "name": "output-1",
# "datatype": "INT64",
# "shape": ["1", "1"],
# "parameters": {"content_type": {"stringParam": "np"}},
# "contents": {"int64Contents": ["0"]},
# }
# ],
# }
Async versions of the same APIs are also available, use grpc.aio instead to create a channel then await and requests made.
async with grpc.aio.insecure_channel('localhost:8081') as channel:
stub = GRPCInferenceServiceStub(channel)
await stub.ServerReady(ServerReadyRequest())
Dependencies
The open-inference-grpc python package relies only on grpcio, the underlying transport implementation of gRPC.
Contribute
This client is largely generated automatically by grpc-tools, with a small amount of build post-processing in build.py.
Run
python build.pyto build this package, it will:
- If
proto/open_inference_grpc.protois not found, download it from open-inference/open-inference-protocol/- Run grpcio_tools.protoc to create the python client
- Postprocess filenames and imports
- Prepend the Apache 2.0 License preamble
- Format with black
If you want to contribute to the open-inference-protocol itself, please create an issue or PR in the open-inference/open-inference-protocol repository.
License
By contributing to Open Inference Protocol Python client repository, you agree that your contributions will be licensed under its Apache 2.0 License.
Metadata
Release files for open-inference-grpc 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| open_inference_grpc-2.0.0.tar.gz | 9.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| open_inference_grpc-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.5 kB
Release files / open_inference_grpc-2.0.0.tar.gz
| Download URL | open_inference_grpc-2.0.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab71943730309a6bb19677d57ea64f1824799cfbdbe5adaed7515852716a7ae8
|
|
BLAKE2b-256 checksum How to use checksums |
937a9066af152ef0d2ab34e801f65ebedc5474b020e3d3d01c94d14e1faf918d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.8.10 Linux/5.15.133.1-microsoft-standard-WSL2
|
Release files / open_inference_grpc-2.0.0-py3-none-any.whl
| Download URL | open_inference_grpc-2.0.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73679c9b511dea1224ebecf2d6e944b6cf039f3ba24a66d1524870da47f5c071
|
|
BLAKE2b-256 checksum How to use checksums |
c4fbe37ca9bee512bc0c1e61a930206886dcb4dd1dce50160a30f8760103d887
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.8.10 Linux/5.15.133.1-microsoft-standard-WSL2
|