Package version numbers for protobuf and gRPC (for Python)

1,996 views
Skip to first unread message

Jens Troeger

unread,
Jul 9, 2023, 9:37:06 PM7/9/23
to grpc.io
Hello,

Following this question I’m trying to find the documentation that defines which versions of the grpcio package implement which version of the Protocol Buffers language.

And, in that context, how do the Google API common protos (and its generated Python package) relate to the different Protobuf versions?

Much thanks!
Jens

Richard Belleville

unread,
Jul 12, 2023, 1:31:13 PM7/12/23
to grpc.io
Hi Jens,

The grpcio package itself is completely agnostic to protobuf. It only has byte-oriented interfaces. Protobuf integration only happens within the generated code (e.g. helloworld_pb2_grpc.py). This generated code comes from running the grpcio-tools package, which does have a dependency on protobuf. The compatibility range with protobuf is defined by this package's dependency range on protobuf and can be seen by either looking at its setup.py file or using a dependency inspection tool such as pipdeptree:

(venv) rbellevi-macbookpro:tmp.m984j04o rbellevi$ python3 -m pipdeptree
grpcio-tools==1.56.0
├── grpcio [required: >=1.56.0, installed: 1.56.0]
├── protobuf [required: >=4.21.6,<5.0dev, installed: 4.23.4]
└── setuptools [required: Any, installed: 67.8.0]


In general, you can use the heuristic that if you do pip install grpcio-tools and generate your code, you'll have the right version of protobuf already installed.

This isn't ideal since many people generate their code only once and then rebuild their application many times, potentially forgetting the version of protobuf that they originally used to generate their code. In practice, even these people are generally fine, only getting bitten when protobuf does a major version bump, which has happened once in the past 5 years.

Jens Troeger

unread,
Jul 12, 2023, 6:09:41 PM7/12/23
to grpc.io
Thank you, Richard, that’s helpful!

Funny enough, your response also relates to the discussion Allow package references as version specifiers over at the Python Discussion groups. It does make sense what you suggest.

And in that vein, looking at Python’s Google API Commons the setup contains

  dependencies = [
      "protobuf>=3.19.5,<5.0.0.dev0,!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
  ]
  extras_require = {"grpc": ["grpcio >= 1.44.0, <2.0.0.dev0"]}

thus indicating which version of Protocol Buffers and gRPC/Tools the package supports.

Cheers,
Jens

Reply all
Reply to author
Forward
0 new messages