Skip to content

Commit 8b1ec1a

Browse files
committed
chore: update README
1 parent 5f47f8e commit 8b1ec1a

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
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:
2426
pip 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

2933
purerpc adds `protoc-gen-purerpc` plugin for `protoc` to your `PATH` enviroment variable
@@ -62,16 +66,16 @@ class Greeter(GreeterServicer):
6266

6367
server = Server(50055)
6468
server.add_service(Greeter().service)
65-
server.serve()
69+
server.serve(backend="asyncio")
6670
```
6771

6872
### Client
6973

7074
```python
7175
import curio
76+
import purerpc
7277
from greeter_pb2 import HelloRequest, HelloReply
7378
from greeter_grpc import GreeterStub
74-
from purerpc import Channel
7579

7680

7781
async def gen():
@@ -80,22 +84,19 @@ async def gen():
8084

8185

8286
async 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

9596
if __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

101102
More examples in `misc/` folder
File renamed without changes.

0 commit comments

Comments
 (0)