Generate Python modules from protobuf files.
install with your favorite python package manager
pip install pyprotostuben
Then use protoc plugins to generate python code. See greeting examples for more info.
Generates python stubs (*_pb2.pyi
& *_pb2_grpc.pyi
files which then used by MyPy type checker / IDE syntax highlits
& suggestions).
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
plugin options:
message-mutable
-- add setters for fields, use mutable containersmessage-all-init-args-optional
-- each field is optional in message constructor (even if field is not optional)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 stubsno-parallel
-- disable multiprocessingdebug
-- turn on plugin debugging
Generates *_brokrpc.py
modules for BrokRPC framework. This is similar to gRPC
codegen (*_pb2_grpc.py
modules).
plugin options:
no-parallel
-- disable multiprocessingdebug
-- turn on plugin debugging
Saves protoc plugin input to a file. Helps develop protoc plugins.
plugin options:
format={raw|binary|json}
(default =raw
) -- specify output formatdest={path}
(default =request.json
) -- specify file destination