pythongrpctype-hintinggrpc-python

How to generate python type hints in generated grpc code


Can PEP compliant type hints be automatically added to generated source code, or dynamically created, for python and gRPC? Specifically in the basics tutorial in the client section for feature = stub.GetFeature(point) I would like my IDE to know and check that point is type Point in the *_pb2.py and feature is type Feature with an attribute location: Point. Thank you.


Solution

  • Type hints aren't yet (!?) available for Python gRPC, see Issue 29041

    You can generate type hints for the Protobuf messages only using the --pyi_out=${PWD} flag when running protoc directly or indirectly with python3 -m grpc.tools.protoc