Some useful Python's gRPC tools.
Install gRPC tools:
$ pip install grpcio-tools
See gRPC Python Quickstart for more details.
Install grpc-pytools:
$ pip install grpc-pytools
Generate an AST-like JSON file from the .proto file:
$ python -m grpc_tools.protoc -I. --pytools-ast_out=. xx.proto
Generate more Pythonic services for all gRPC services defined in the xx_pb2.py file (generated by grpcio-tools
):
$ python -m grpc_pytools.pythonic --proto-ast-file=/path/to/xx_ast.json --pb2-module-name=python.path.to.xx_pb2
Generate Marshmallow schemas for all gRPC messages defined in the xx_pb2.py file:
$ python -m grpc_pytools.marshmallow --proto-ast-file=/path/to/xx_ast.json --pb2-module-name=python.path.to.xx_pb2
Generate simple RESTArt APIs for all gRPC methods defined in the xx_pb2.py file:
$ python -m grpc_pytools.restart --proto-ast-file=/path/to/xx_ast.json --pb2-module-name=python.path.to.xx_pb2 --grpc-server=localhost:50051
See examples to find out how to generate a simple JSON proxy for gRPC services.