I'm working with buf
to try to generate code for my grpc service. However, I don't want to create a Python service. I only want to use a Python client to talk to my service. Is there some option I can give to buf, or the remote plugin to do this?
Here's my buf.gen.yaml
version: v1
plugins:
- plugin: buf.build/grpc/python:v1.54.0
out: gen/python
- plugin: buf.build/protocolbuffers/python:v21.12
out: gen/python
And my example.proto
syntax = "proto3";
package example;
enum MyEnum {
Unknown = 0;
Red = 1;
Blue = 2;
}
message MyMessage {
MyEnum my_enum = 1;
uint32 some_other_field = 2;
}
service MyService {
rpc MyCommand(MyMessage) returns (MyMessage) {}
}
And the generated file
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import example_pb2 as example__pb2
class MyServiceStub(object):
"""Missing associated documentation comment in .proto file."""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.MyCommand = channel.unary_unary(
'/example.MyService/MyCommand',
request_serializer=example__pb2.MyMessage.SerializeToString,
response_deserializer=example__pb2.MyMessage.FromString,
)
class MyServiceServicer(object):
"""Missing associated documentation comment in .proto file."""
def MyCommand(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_MyServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'MyCommand': grpc.unary_unary_rpc_method_handler(
servicer.MyCommand,
request_deserializer=example__pb2.MyMessage.FromString,
response_serializer=example__pb2.MyMessage.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'example.MyService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
# This class is part of an EXPERIMENTAL API.
class MyService(object):
"""Missing associated documentation comment in .proto file."""
@staticmethod
def MyCommand(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/example.MyService/MyCommand',
example__pb2.MyMessage.SerializeToString,
example__pb2.MyMessage.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
Is there a way to tell the remote plugin that I only want to generate MyServiceStub
?