1

I use the protoc tool, from grpc-tools package (ver. 1.43.0) with python 3.8.10 to generate the data types and client and server stubs for my proto3 service. The generated file containing the stubs (ending in '_grpc.py') imports the generated file containing the message data types using an import statement with no package name: 'import <my_service_name>_pb2.py'. If I understand correctly, in order for this import to work properly in python 3 when the generated code is being included in a package, this import needs to include the name of the package containing it: 'from <my_containing_package> import <my_service_name>_pb2.py'. Is there a way to make protoc generate this import with the package name I require?

P.S. I'm currently using sed to post edit the generated file to add the package name, so only interested, here, in a way to make protoc generate the correct form for python 3 in the first place.

sinjin
  • 189
  • 1
  • 6
  • Coincidentally I just (re-)bumped into the same problem. (Have bumped into it before...) – xtofl Jan 31 '22 at 13:09

1 Answers1

0

TL; DR; use https://github.com/cpcloud/protoletariat.

From that tool, you can follow the discussion on the protocolbuffers issue, which basically clarifies that the intended use is to pump all your stubs in a flat source directory.

xtofl
  • 40,723
  • 12
  • 105
  • 192