Server reflection is an optional extension, which describes services, implemented on the server.

In examples we will use grpc_cli command-line tool and helloworld example. We will use extend() method to add server reflection.

Then we will be able to…

List services on the server:

$ grpc_cli ls localhost:50051

List methods of the service:

$ grpc_cli ls localhost:50051 helloworld.Greeter -l
filename: helloworld/helloworld.proto
package: helloworld;
service Greeter {
  rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {}

Describe messages:

$ grpc_cli type localhost:50051 helloworld.HelloRequest
message HelloRequest {
  string name = 1;

Call simple methods:

$ grpc_cli call localhost:50051 helloworld.Greeter.SayHello "name: 'Dr. Strange'"
connecting to localhost:50051
message: "Hello, Dr. Strange!"

Rpc succeeded with OK status

And all of these done without downloading .proto files and compiling them into other source files in order to create stubs.


class grpclib.reflection.service.ServerReflection(*, _service_names: Collection[str])

Implements server reflection protocol.

classmethod extend(services: Collection[IServable]) List[IServable]

Extends services list with reflection service:

from grpclib.reflection.service import ServerReflection

services = [Greeter()]
services = ServerReflection.extend(services)

server = Server(services)

Returns new services list with reflection support added.