Search code examples
pythonprotocol-buffersversiongrpcversioning

Protobuf files versioning in python


I writing a grpc Interface and messages in a protobuf file, eventually I will have breaking changes in the interfaces and messages.

How does one handle protobuf versioning in python?


In C# it is recommended to use the optional package specifier with a version number,
And then the package name is combined with the service name to identify a service address.

Something like this:

syntax = "proto3";
package my_grpc_package.v1;
syntax = "proto3";
package my_grpc_package.v2;

However I read that in python

In Python, the package directive is ignored, since Python modules are organized according to their location in the file system.

So I am not sure How would I would achieve similar functionality? generate the grpc client again in a separate file and named it my_grpc_package.v2.py manualy?


Solution

  • Yes. The version number can be included into the file path, the gRPC repo itself also uses this way to organize its proto files: https://github.com/grpc/grpc/tree/master/src/proto/grpc/health/v1