Skip to main content

No project description provided

Project description

protoc-gen-grpc-py

The gRPC code generator plugin for Protocol Buffers for Python. Learn more about the project at github.com/bufbuild/protobuf-py.

Overview

protoc-gen-grpc-py generates fully typed, idiomatic gRPC clients and servicers that use protobuf-py messages for serialization. Unlike the stock gRPC Python plugin, the generated stubs:

  • are fully typed, so editors and type checkers understand every RPC method
  • serialize protobuf-py messages directly, with no dependency on the _pb2 Protobuf runtime
  • ship both asyncio (grpc.aio) and synchronous variants.

For each service it emits a servicer base class (with an add_to_server method) and a client, in both async and sync flavors (the sync names are suffixed with Sync). Message types are generated separately by protoc-gen-py.

Installation

The generated code requires the runtime libraries protobuf-py and grpcio. The plugin is compatible with Protocol Buffer compilers like buf and protoc.

$ uv add protobuf-py grpcio
$ uv add --dev protoc-gen-py protoc-gen-grpc-py buf-bin

Generating code

With buf

Add protoc-gen-grpc-py alongside protoc-gen-py in your buf.gen.yaml:

version: v2
inputs:
  - directory: proto
plugins:
  # Generates message types (*_pb.py).
  - local: protoc-gen-py
    out: src/gen
  # Generates gRPC service stubs (*_pb_grpc.py).
  - local: protoc-gen-grpc-py
    out: src/gen

To generate code for all Protobuf files within your project, run:

$ uv run -- buf generate

With protoc

$ uv run protoc --proto_path proto \
    --py_out src/gen \
    --grpc-py_out src/gen \
    proto/a.proto proto/b.proto proto/c.proto

A *_pb_grpc.py file is generated only for proto files that declare a service. The plugin does not emit __init__.py files; let protoc-gen-py manage those.

Plugin options

io

Controls which flavor of code is generated:

  • unset (default): generate both asynchronous (grpc.aio) and synchronous (grpc) code;
  • io=async: generate only asynchronous code;
  • io=sync: generate only synchronous code.

For example, in buf.gen.yaml:

plugins:
  - local: protoc-gen-grpc-py
    out: src/gen
    opt: io=async

Example

See the gRPC example for a complete client and server using the generated stubs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

protoc_gen_grpc_py-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

protoc_gen_grpc_py-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file protoc_gen_grpc_py-0.1.0.tar.gz.

File metadata

  • Download URL: protoc_gen_grpc_py-0.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for protoc_gen_grpc_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26a76cb74f94aaa6a8f5abb829cff65447350c6090fcdeac74c6af4280ca91df
MD5 f2e1a3101be831a1a1baaa4be622dd7f
BLAKE2b-256 43cee3610e9e672c0bc26dbbee326febabe059d7881739becf4d5f0ffa8cbfd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for protoc_gen_grpc_py-0.1.0.tar.gz:

Publisher: release.yaml on bufbuild/protobuf-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protoc_gen_grpc_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for protoc_gen_grpc_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d90a6a5676aa09dd80b6f95eff99f044fcc8160aea7edcad09de2a5327ae9eff
MD5 d9505a5acb7ce49abc3f3a4a01b530fe
BLAKE2b-256 d59602bffb45caa3f5e9370c94704eaf1f6406b93c396ffc821046e45aad15cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for protoc_gen_grpc_py-0.1.0-py3-none-any.whl:

Publisher: release.yaml on bufbuild/protobuf-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page