how to get reflected services and rpc interface in grpc-python?

1,722 views
Skip to first unread message

Louis Yang

unread,
Apr 4, 2020, 11:21:23 PM4/4/20
to grpc.io

Like grpcox tool, 

Given a service endpoint: 1.2.3.4:50001, return the all services list and rpc api under these services
is there an existing api for this in grpc-python?

Lidi Zheng

unread,
Apr 6, 2020, 6:51:56 PM4/6/20
to Louis Yang, grpc.io
There is a grpcio-reflection package that enables reflection services for servers. See example: https://github.com/grpc/grpc/blob/master/examples/python/helloworld/greeter_server_with_reflection.py.

For client-side checking services list, here is the proto definition for service reflection API: https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto
You can get all the details in the descriptor proto.
Another option is using the CLI tool: https://github.com/fullstorydev/grpcurl.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/005f21b7-76ef-48fa-9be5-f270b52adf9b%40googlegroups.com.

Louis Yang

unread,
Apr 7, 2020, 2:09:51 AM4/7/20
to grpc.io
thanks, could you provide some example for using relection.proto? 


On Tuesday, 7 April 2020 06:51:56 UTC+8, Lidi Zheng wrote:
There is a grpcio-reflection package that enables reflection services for servers. See example: https://github.com/grpc/grpc/blob/master/examples/python/helloworld/greeter_server_with_reflection.py.

For client-side checking services list, here is the proto definition for service reflection API: https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto
You can get all the details in the descriptor proto.
Another option is using the CLI tool: https://github.com/fullstorydev/grpcurl.

On Sat, Apr 4, 2020 at 8:21 PM Louis Yang <foreverc...@gmail.com> wrote:

Like grpcox tool, 

Given a service endpoint: 1.2.3.4:50001, return the all services list and rpc api under these services
is there an existing api for this in grpc-python?

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grp...@googlegroups.com.

Lidi Zheng

unread,
Apr 7, 2020, 1:12:10 PM4/7/20
to Louis Yang, grpc.io
I don't have a specific example for reflection.proto. It is a gRPC service. All the messages are defined with comments.

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/51654a95-e257-42d1-a2b3-80e255ef74c8%40googlegroups.com.

Tomer Vromen

unread,
May 23, 2022, 7:04:28 AM5/23/22
to grpc.io

Pascal Cohen

unread,
May 30, 2022, 2:54:50 AM5/30/22
to grpc.io
Hi
I am fairly new to GRPC with Python
I wanted to explore reflection and followed the links provided above.
For testing purposes I create a simple test receiving an Id and returning an associated result.
It works perfectly if I use generated code. Now trying to inspect the server and get the services and instantiate dynamically the logic, I struggle a bit more.

Using snippet like:

reflection_db = ProtoReflectionDescriptorDatabase(channel)
desc_pool = DescriptorPool(reflection_db)

services = reflection_db.get_services()
service = desc_pool.FindServiceByName(xxx)

for m in service.methods:
   input_type = m.input_type

and with
request = MessageFactory(desc_pool).GetPrototype(input_type)()

I can build a request
I struggle to instantiate the service and call it with request:

I tried things like:

stub = GeneratedServiceStubType(service.name, (), {GeneratedServiceStubType._DESCRIPTOR_KEY:service })
and then stub.<<myMethod>>(request) but it fails. I need to pass other params but no real clue
The final purpose is to a kind of getAttr(stub,methode.name, parms)

I looked at code/googled but failed to find any helpful content
Thanks for any help

Cheers
Pascal
Reply all
Reply to author
Forward
0 new messages