Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 2.54 KB

L95-python-reflection-client.md

File metadata and controls

60 lines (40 loc) · 2.54 KB

Python Reflection Client

Abstract

Add a programmatic way to access reflection descriptors from client-side Python.

Background

Reflection is a means by which a server can describe which services and messages it supports. The Reflection protocol is already part of the gRPC repository, and there are server-side implementations of it in several languages, including C++ and Python - see gRPC Python Server Reflection

However, the only client-side implementation is in C++. It seems that a client-side Python implementation is a missing to complete the picture.

This proposal closes this gap.

Related Proposals:

Proposal

Provide a Python implementation for client-side reflection, modeled after the existing C++ implementation.

  • Implement ProtoReflectionDescriptorDatabase which implements the DescriptorDatabase interface.
  • Write tests.
  • Write documentation.

Rationale

Python provides an easy interface for reflection, due to its dynamic nature. For example, retrieving the descriptor for a service can be as simple as

service_desc = desc_pool.FindServiceByName("helloworld.Greeter")

The alternative is that anyone who wishes to have a Python reflection client will have to implement this by themselves.

Adding proper tests to the codebase ensures correctness even when (if) the reflection protocol changes.

The main downside is having a bigger API surface to support.

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

Implementation

Implementation is already available as a PR #28443.