grpc framework like flask
This project is no longer maintained. Creating a gRPC framework with Python was a big challenge. However, it became difficult to maintain the homei because I didn't use gRPC often after changing jobs. When I started this project, I made it hoping that gRPC would be actively used in many languages. Sadly, however, most of the gRPC's main customers are still in the go language. So I'm going to close this project and focus a little more on grpc-requests.
micro grpc framework like flask
pip install homi
check more example
from homi import App, Server
from homi.extend.service import reflection_service, health_service
from helloworld_pb2 import DESCRIPTOR
svc_desc = DESCRIPTOR.services_by_name['Greeter']
app = App(
services=[
svc_desc,
reflection_service,
health_service,
]
)
# unary-unary method
@app.method('helloworld.Greeter')
def SayHello(name, **kwargs):
print(f"{name} is request SayHello")
return {"message": f"Hello {name}!"}
# or
@app.method('helloworld.Greeter','SayHello')
def hello(request,context):
print(f"{request.name} is request SayHello")
return {"message": f"Hello {request.name}!"}
# or
def hello_func(request,context):
return {"message":"hi"}
app.register_method('helloworld.Greeter','SayHello',hello_func)
if __name__ == '__main__':
server = Server(app)
server.run()
The service class is similar to the blueprint of flask. You can separate files on a service basis or add services created by others. Also, we will be able to override the method already registered in the future.
from homi import App, Server,Service
from homi.extend.service import reflection_service, health_service
from helloworld_pb2 import DESCRIPTOR
app = App(services=[reflection_service,health_service,])
greeter = Service(DESCRIPTOR.services_by_name['Greeter'])
@greeter.method()
def SayHello(name, **kwargs):
print(f"{name} is request SayHello")
return {"message": f"Hello {name}!"}
# you can share service to pypi
app.add_service(greeter)
# if app file name is app.py
homi run
# run ohter app file
homi run other_app.py
# change port
homi run -p 50055
# change total worker
homi run -w 5
# run TLS server
homi run --private_key server.key --certificate server.crt
0.2.2
0.2.1
0.2.0
0.1.7
0.1.6
0.1.5
0.1.1
0.1.0
0.0.4.alpha
0.0.3
0.0.1 (init project)