要調用RPC接口,python提供了一個框架grpc,這是google開源的html
rpc相關文檔:python
須要安裝的python包以下:api
syntax = "proto3"; package grpcDemo; message HelloRequest { string name = 1; } message HelloReply { string message = 1; } service gRPC { rpc SayHello (HelloRequest) returns (HelloReply) {} }
接口調用內容示例:框架
# -*- coding: utf-8 -*- import grpc import data_pb2,data_pb2_grpc _HOST = 'localhost' _PORT = '8080' def run(): conn = grpc.insecure_channel(_HOST + ':' + _PORT) client = data_pb2_grpc.gRPCStub(channel=conn) response = client.SayHello(data_pb2.HelloRequest(name='hello,world!')) print("received: " + response.text) if __name__ == '__main__': run()