Asynchronous pure python gRPC server and client implementation using curio and hyper-h2.
Project description
purerpc
Asynchronous pure Python gRPC server and client implementation using curio and hyper-h2
Requirements
- CPython >= 3.6
- PyPy >= 3.6
Installation
pip install purerpc
protoc plugin
purerpc has protoc plugin to generate service definition and stubs:
protoc --purerpc_out=. --python_out=. -I. greeter.proto
or, if you installed grpcio_tool package:
python -m grpc_tools.protoc --purerpc_out=. --python_out=. -I. greeter.proto
Usage
NOTE: greeter_grpc module is generated by purerpc protoc plugin
Server
from greeter_pb2 import HelloRequest, HelloReply
from greeter_grpc import GreeterServicer
from purerpc import Server
class Greeter(GreeterServicer):
async def SayHello(self, message):
return HelloReply(message="Hello, " + message.name)
async def SayHelloToMany(self, input_messages):
async for message in input_messages:
yield HelloReply(message=f"Hello, {message.name}")
server = Server(50055)
server.add_service(Greeter().service)
server.serve()
Client
import curio
from greeter_pb2 import HelloRequest, HelloReply
from greeter_grpc import GreeterStub
from purerpc import Channel
async def gen():
for i in range(5):
yield HelloRequest(name=str(i))
async def main():
channel = Channel("localhost", 50055)
# This is optional, will be run automatically on the first request
await channel.connect()
stub = GreeterStub(channel)
reply = await stub.SayHello(HelloRequest(name="World"))
print(reply.message)
async for reply in stub.SayHelloToMany(gen()):
print(reply.message)
if __name__ == "__main__":
curio.run(main)
You can mix server and client code, for example make a server that requests something using purerpc from another server, etc.
More examples in misc/ folder
Release 0.1.2
- Fix unit tests on Python 3.7
Release 0.1.0
- Implement immediate mode
Release 0.0.1
- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file purerpc-0.1.3-py3-none-any.whl.
File metadata
- Download URL: purerpc-0.1.3-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9634afcf2bdd9eddb589160b0729109b08e245593d90c5154c6169605604907f
|
|
| MD5 |
23fe881a3e9911a4fc6b91460673e56b
|
|
| BLAKE2b-256 |
30213e1a1efddb1c7b260569871a420285dd5af272de08dd510b6036e17cf688
|