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.0.1.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.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: protoc_gen_grpc_py-0.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 7d4e0847d556d30e7a2eb9ee50e3100fe9310814ac1bec0c6ba69040fd2faee4
MD5 008151ae6a69f7ec592d9acb362a6a40
BLAKE2b-256 395865e27984f99f32b899055869ab08154779f24fc0afa192b48163fb50a352

See more details on using hashes here.

Provenance

The following attestation bundles were made for protoc_gen_grpc_py-0.0.1.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.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for protoc_gen_grpc_py-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 167db43690de1b4182f2a8f8dda37792f25393622ddff1b9b213e53d7a862b9b
MD5 0b30c0c7cc871d624fd4c7f336e8754a
BLAKE2b-256 a5050fe5d2bea0a03e5b67411420d59672c3133d0c7242baff0457f423166cae

See more details on using hashes here.

Provenance

The following attestation bundles were made for protoc_gen_grpc_py-0.0.1-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