Skip to main content

Asynchronous pure python gRPC server and client implementation using curio and hyper-h2.

Project description

# purerpc

[![Build Status](https://travis-ci.org/standy66/purerpc.png?branch=master)](https://travis-ci.org/standy66/purerpc)

Asynchronous pure Python gRPC server and client implementation using
[curio](https://github.com/dabeaz/curio) and [hyper-h2](https://github.com/python-hyper/hyper-h2)

## Requirements

* CPython >= 3.6
* PyPy >= 3.6

## Installation

```bash
pip install purerpc
```

## protoc plugin

purerpc has protoc plugin to generate service definition and stubs:

```bash
protoc --purerpc_out=. --python_out=. -I. greeter.proto
```

or, if you installed `grpcio_tool` package:

```bash
python -m grpc_tools.protoc --purerpc_out=. --python_out=. -I. greeter.proto
```

## Usage

NOTE: `greeter_grpc` module is generated by purerpc `protoc` plugin

### Server

```python
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

```python
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

purerpc-0.1.2.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

purerpc-0.1.2-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file purerpc-0.1.2.tar.gz.

File metadata

  • Download URL: purerpc-0.1.2.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for purerpc-0.1.2.tar.gz
Algorithm Hash digest
SHA256 99ab2b5363c4b6c8fe88aef41f956a3e899390118df483b41a1296d51f0bbe42
MD5 b37d1f95fbed9cdc89c7bb7d894bf1b5
BLAKE2b-256 0fccc7d80c8221d0ab101dd7471a8da588126f206bbf8a921524be8fc32bdd2b

See more details on using hashes here.

File details

Details for the file purerpc-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for purerpc-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 898c01830849eb3f40abe7d65b23a518a2bfca44dfb6470bf5afab701cd0fdd1
MD5 756101af82345499d156b17355ed4bfa
BLAKE2b-256 7995000541c1374cc1f61c2b4e05ec27e82de69fc22f81b141a0bb76a25eb875

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page