Python3调用grpc

1、protobuf

2、安装

需要安装的python包如下:
1.grpc安装

pip install grpcio

2.grpc的python protobuf相关的编译工具

pip install grpcio-tools

3.protobuf相关python依赖库

pip install protobuf

4.一些常见原型的生成python类的集合:

pip install googleapis-common-protos

5.执行命令,生成py

# protoc --python_out=. gd.proto
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. gd.proto

会生成gd_pb2.py、gd_pb2_grpc.py

3、调用

import grpc

channel_gd = grpc.insecure_channel(127.0.0.1:8080, options=[
    ('grpc.max_send_message_length', 100 * 1024 * 1024),
    ('grpc.max_receive_message_length', 100 * 1024 * 1024)
])
stub_gd = gd_pb2_grpc.NxxStub(channel_gd)
gd_params = gd_pb2.GetNxxGdInRectRequest(p1,p2,p3...)
gd_resp = stub_gd.GetNxxGdInRect(gd_params)
print(gd_resp.data.ele)

你可能感兴趣的:(Python,protobuf,grpc)