Generate Python MyPy stub modules from protobuf files.
Project description
pyprotostuben
Generate Python MyPy stub modules from protobuf files.
usage
install into dev dependencies group
poetry add --group dev pyprotostuben
protoc-gen-pyprotostuben
a protoc plugin that generates MyPy stubs
features
- choose message structure immutability / mutability
- choose async / sync grpc module stubs
- grpc servicer abstract methods have full signature (with appropriate type args in generics), thus it is easier to implement methods in IDE
flags
message-mutable-- add setters for fields, use mutable containersmessage-all-init-args-optional-- each field is optional in message constructor (event if required)grpc-sync-- use sync grpc stubs instead of grpc.aio module and async defsgrpc-skip-servicer-- don't generate code for servicersgrpc-skip-stub-- don't generate code for stubs
examples
requirements
- protoc
- buf CLI
project structure
- /
- src/
- greeting.proto
syntax = "proto3"; package greeting; // RPC request for greeting message GreetRequest { string name = 1; } // RPC response for greeting message GreetResponse { string text = 1; } // RPC service that provides greet functionality service Greeter { // RPC method for greeting rpc Greet(GreetRequest) returns (GreetResponse) {} }
- greeting.proto
- buf.yaml
version: v1beta1 build: roots: - src
- buf.gen.yaml
version: v1 managed: enabled: true plugins: - plugin: pyprotostuben out: out strategy: all
- src/
run codegen
buf generate
output
src/greeting_pb2.pyi
import builtins
import google.protobuf.message
import typing
class GreetRequest(google.protobuf.message.Message):
"""RPC request for greeting"""
def __init__(self, *, name: builtins.str) -> None:...
@builtins.property
def name(self) -> builtins.str:...
def HasField(self, field_name: typing.NoReturn) -> typing.NoReturn:...
def WhichOneof(self, oneof_group: typing.NoReturn) -> typing.NoReturn:...
class GreetResponse(google.protobuf.message.Message):
"""RPC response for greeting"""
def __init__(self, *, text: builtins.str) -> None:...
@builtins.property
def text(self) -> builtins.str:...
def HasField(self, field_name: typing.NoReturn) -> typing.NoReturn:...
def WhichOneof(self, oneof_group: typing.NoReturn) -> typing.NoReturn:...
src/greeting_pb2_grpc.pyi
import abc
import builtins
import greeting_pb2
import grpc
import grpc.aio
import typing
class GreeterServicer(metaclass=abc.ABCMeta):
"""RPC service that provides greet functionality"""
@abc.abstractmethod
async def Greet(self, request: greeting_pb2.GreetRequest, context: grpc.aio.ServicerContext[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]) -> greeting_pb2.GreetResponse:
"""RPC method for greeting"""
...
def add_GreeterServicer_to_server(servicer: GreeterServicer, server: grpc.aio.Server) -> None:...
class GreeterStub:
"""RPC service that provides greet functionality"""
def __init__(self, channel: grpc.aio.Channel) -> None:...
def Greet(self, request: greeting_pb2.GreetRequest, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]:
"""RPC method for greeting"""
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyprotostuben-0.2.0.tar.gz.
File metadata
- Download URL: pyprotostuben-0.2.0.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
593691c39ac615482ca28fc11eda9340b5d564fb39569d6d9592265bf5767210
|
|
| MD5 |
da7ab4efd49f6dcce4165e4a7db0402c
|
|
| BLAKE2b-256 |
cd9213ad976fc101b8da7b7ca7dbef19da6f90795d6fa89269b9b5da6aaa4ab4
|
Provenance
The following attestation bundles were made for pyprotostuben-0.2.0.tar.gz:
Publisher:
publish.yaml on zerlok/pyprotostuben
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyprotostuben-0.2.0.tar.gz -
Subject digest:
593691c39ac615482ca28fc11eda9340b5d564fb39569d6d9592265bf5767210 - Sigstore transparency entry: 150495203
- Sigstore integration time:
-
Permalink:
zerlok/pyprotostuben@9a62c882d731f20c9e531e57ce74a5ec26bd4696 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9a62c882d731f20c9e531e57ce74a5ec26bd4696 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyprotostuben-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyprotostuben-0.2.0-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
482986e84a9d288e29e88f51ea2e8bf070026d4e84e778f46050a666aba7adfe
|
|
| MD5 |
a3a1223e7ec7bc5d6c556a3a60021f1b
|
|
| BLAKE2b-256 |
9aaf9c50863c877770de5595231992dbe8113c72a9ff34398a82c00a730b38dd
|
Provenance
The following attestation bundles were made for pyprotostuben-0.2.0-py3-none-any.whl:
Publisher:
publish.yaml on zerlok/pyprotostuben
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyprotostuben-0.2.0-py3-none-any.whl -
Subject digest:
482986e84a9d288e29e88f51ea2e8bf070026d4e84e778f46050a666aba7adfe - Sigstore transparency entry: 150495205
- Sigstore integration time:
-
Permalink:
zerlok/pyprotostuben@9a62c882d731f20c9e531e57ce74a5ec26bd4696 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9a62c882d731f20c9e531e57ce74a5ec26bd4696 -
Trigger Event:
release
-
Statement type: