Skip to content

3. Develop a simple client

Florian Vansteene edited this page Jul 2, 2017 · 2 revisions

You can use different langage to implement the client with Protobuf. For the example, i will show you how to create a simple client in Python.

There are an example of simple client in Python with gRPC/Protobuf here

1. Install gRPC and gRPC tools

$ python -m pip install grpcio
$ python -m pip install grpcio-tools

2. Add the protobuf file

Your protobuf file must to be in the folder protos, and must be the same as the server's protobuf file. For the example the file is helloworld.proto

syntax = "proto3";

package example;

service HelloWorldService {
    rpc SayHello (InitTransactionRequest) returns (FitnessResponse) {}
}

message HelloRequest {
    string message = 1;
}

message HelloResponse {
    string message = 2;
}

3. Generate the class and stub class from you're .proto file

$ python -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. protos/helloworld.proto

4. Implement the new grpc service

Now we need to implement the new service. In you're client import the new grpc service :

from protos import helloworld_pb2_grpc
from protos import helloworld_pb2

Your can found the current client pour this project here : florianva/RoAPIClientPython

Clone this wiki locally