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
Latest PyPI version:
pip install purerpc
Latest development version:
pip install git+https://github.com/standy66/purerpc.git
protoc plugin
purerpc adds protoc-gen-purerpc
plugin for protoc
to your PATH
enviroment variable
so you can use it to generate service definition and stubs:
protoc --purerpc_out=. --python_out=. -I. greeter.proto
or, if you installed grpcio_tools
Python package:
python -m grpc_tools.protoc --purerpc_out=. --python_out=. -I. greeter.proto
Usage
NOTE: greeter_grpc
module is generated by purerpc's protoc-gen-purerpc
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.4
- Speed up protoc plugin
Release 0.1.3 [PyPI only]
- Fix long description on PyPI
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 Distribution
Built Distribution
File details
Details for the file purerpc-0.1.4.tar.gz
.
File metadata
- Download URL: purerpc-0.1.4.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f827886dc36a2c8360933310c118bc35805476d03155b76484c06718cf3a533 |
|
MD5 | 4ee2db3288d18e969e07cee7ae75213a |
|
BLAKE2b-256 | 0cdbd54d5447b3af652547921bdf9eb2397f44f065644882a273a52a10170d89 |
File details
Details for the file purerpc-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: purerpc-0.1.4-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7ab3e5b261c739b4f811552d81b85cc1c42f508fb0e587483577ca29ef2932a |
|
MD5 | b9d8d314de1fbb5759b8ea0c15550507 |
|
BLAKE2b-256 | 34dc21d6ce2c8b0f1a97bb2be50c5d1ea934231218b782b86c9a04d3eadefdec |