No project description provided
Project description
pyprotostuben
Generates Python MyPy stub modules from protobuf files.
usage
install
poetry add 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; message GreetRequest { string name = 1; } message GreetResponse { string text = 1; } service Greeter { 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):
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):
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):
@abc.abstractmethod
async def Greet(self, request: greeting_pb2.GreetRequest, context: grpc.aio.ServicerContext[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]) -> greeting_pb2.GreetResponse:...
def add_GreeterServicer_to_server(servicer: GreeterServicer, server: grpc.aio.Server) -> None:...
class GreeterStub:
def __init__(self, channel: grpc.aio.Channel) -> None:...
async 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]:...
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
pyprotostuben-0.1.0.tar.gz
(18.6 kB
view details)
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.1.0.tar.gz.
File metadata
- Download URL: pyprotostuben-0.1.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a8c24b7f9660572bd2175a84fbaafbb688a8ca6205b698debfcab4b8f326407
|
|
| MD5 |
58f22ab77b2f3c1c46fdbe3057e0135a
|
|
| BLAKE2b-256 |
f978910ca1dd39ac7a88ac8547aeb91be6d1f76966c7a0415dbab9c6eac41be2
|
File details
Details for the file pyprotostuben-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyprotostuben-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
187f8e6fa673be4501a795b152624e097e42de103b64ad0ec2a56f9fb239da65
|
|
| MD5 |
9e946a08bc63efc59f5857d28f3c5134
|
|
| BLAKE2b-256 |
1e0ff4c237331c62945e4b395b3474c0d771882d2e93ea35bd867d0e851bf0e3
|