22
33[ ![ Build Status] ( https://travis-ci.org/standy66/purerpc.png?branch=master )] ( https://travis-ci.org/standy66/purerpc )
44
5- Asynchronous pure Python gRPC server and client implementation using
6- [ curio] ( https://github.com/dabeaz/curio ) and [ hyper-h2] ( https://github.com/python-hyper/hyper-h2 )
5+ Asynchronous pure Python gRPC server and client implementation supporting
6+ [ asyncio] ( https://docs.python.org/3/library/asyncio.html ) ,
7+ [ curio] ( https://github.com/dabeaz/curio ) and
8+ [ trio] ( https://github.com/python-trio/trio ) .
79
810## Requirements
911
@@ -24,6 +26,8 @@ Latest development version:
2426pip install git+https://github.com/standy66/purerpc.git
2527```
2628
29+ By default purerpc uses asyncio event loop, if you want to use curio or trio, please install them manually.
30+
2731## protoc plugin
2832
2933purerpc adds ` protoc-gen-purerpc ` plugin for ` protoc ` to your ` PATH ` enviroment variable
@@ -62,16 +66,16 @@ class Greeter(GreeterServicer):
6266
6367server = Server(50055 )
6468server.add_service(Greeter().service)
65- server.serve()
69+ server.serve(backend = " asyncio " )
6670```
6771
6872### Client
6973
7074``` python
7175import curio
76+ import purerpc
7277from greeter_pb2 import HelloRequest, HelloReply
7378from greeter_grpc import GreeterStub
74- from purerpc import Channel
7579
7680
7781async def gen ():
@@ -80,22 +84,19 @@ async def gen():
8084
8185
8286async def main ():
83- channel = Channel(" localhost" , 50055 )
84- # This is optional, will be run automatically on the first request
85- await channel.connect()
86- stub = GreeterStub(channel)
87-
88- reply = await stub.SayHello(HelloRequest(name = " World" ))
89- print (reply.message)
90-
91- async for reply in stub.SayHelloToMany(gen()):
87+ async with purerpc.insecure_channel(" localhost" , 50055 ) as channel:
88+ stub = GreeterStub(channel)
89+ reply = await stub.SayHello(HelloRequest(name = " World" ))
9290 print (reply.message)
9391
92+ async for reply in stub.SayHelloToMany(gen()):
93+ print (reply.message)
94+
9495
9596if __name__ == " __main__" :
96- curio.run(main)
97+ curio.run(main) # Or trio.run(main)
9798```
9899
99- You can mix server and client code, for example make a server that requests something using purerpc from another server, etc.
100+ You can mix server and client code, for example make a server that requests something using purerpc from another gRPC server, etc.
100101
101102More examples in ` misc/ ` folder
0 commit comments