Skip to main content
Version: 2.20

python-protobuf


Options related to the Protobuf Python backend.

See https://www.pantsbuild.org/2.20/docs/python/integrations/protobuf-and-grpc.

Backend: pants.backend.codegen.protobuf.python

Config section: [python-protobuf]

Basic options

grpcio_plugin

--[no-]python-protobuf-grpcio-plugin
PANTS_PYTHON_PROTOBUF_GRPCIO_PLUGIN
pants.toml
[python-protobuf]
grpcio_plugin = <bool>
default: True

Use the official grpcio plugin (https://pypi.org/project/grpcio/) to generate grpc service stubs.

grpclib_plugin

--[no-]python-protobuf-grpclib-plugin
PANTS_PYTHON_PROTOBUF_GRPCLIB_PLUGIN
pants.toml
[python-protobuf]
grpclib_plugin = <bool>
default: False

Use the alternative grpclib plugin (https://github.com/vmagamedov/grpclib) to generate grpc service stubs.

mypy_plugin

--[no-]python-protobuf-mypy-plugin
PANTS_PYTHON_PROTOBUF_MYPY_PLUGIN
pants.toml
[python-protobuf]
mypy_plugin = <bool>
default: False

Use the mypy-protobuf plugin (https://github.com/dropbox/mypy-protobuf) to also generate .pyi type stubs.

Advanced options

infer_runtime_dependency

--[no-]python-protobuf-infer-runtime-dependency
PANTS_PYTHON_PROTOBUF_INFER_RUNTIME_DEPENDENCY
pants.toml
[python-protobuf]
infer_runtime_dependency = <bool>
default: True

If True, will add a dependency on a python_requirement target exposing the protobuf module (usually from the protobuf requirement). If the protobuf_source target sets grpc=True, will also add a dependency on the python_requirement target exposing the grpcio module.

If [python].enable_resolves is set, Pants will only infer dependencies on python_requirement targets that use the same resolve as the particular protobuf_source / protobuf_sources target uses, which is set via its python_resolve field.

Unless this option is disabled, Pants will error if no relevant target is found or if more than one is found which causes ambiguity.

Deprecated options

None

None