Simple framework to create your own gRPC server with grpcio.
pip install git+https://github.com/NF-coder/SimpleRPC.git- Exceptions handling
- Secure channels support
- Autoconfigure from pydantic model
- Source-of-truth for protos
- Tests and docs
server.py
fromsimple_rpcimportGrpcServerfrompydanticimportBaseModelclassRequestModel(BaseModel):
passclassResponceModel(BaseModel):
num2: intnum4: intapp=GrpcServer()
classServer:
@app.grpc_method()asyncdefexample_method(self, request: RequestModel) ->ResponceModel:
returnResponceModel(
num2=3,
num4=1
)
app.configure_service(
cls=Server(),
port=50051
)
app.run()client.py
frompydanticimportBaseModelfromsimple_rpcimportGrpcClientimportasyncioclient=GrpcClient(
proto_file_relpath="simplerpc_tmp/Server.proto", # Generates automatically on server startupport=50051
)
command=client.configure_command(
functionName="example_method",
className="Server"
)
asyncdefrun():
print(
awaitcommand()
)
if__name__=="__main__":
asyncio.run(
run()
)