Skip to main content

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

Project description

purerpc

Build Status

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.6

  • Allow passing request headers to method handlers in request argument
  • Allow passing custom metadata to method stub calls (in metadata optional keyword argument)

Release 0.1.5

  • Enforce SO_KEEPALIVE with small timeouts
  • Expose PureRPCTestCase in purerpc API for unit testing purerpc services

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


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.6.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

purerpc-0.1.6-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: purerpc-0.1.6.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for purerpc-0.1.6.tar.gz
Algorithm Hash digest
SHA256 05e8210911d4c6584f1c254fe11b257effefe62f9c50fe9ec4eed370474b8f57
MD5 3612c28a7e4d003834fa1b07550557da
BLAKE2b-256 9824cbaf896f2189c27c2cb018ea2e3ad5ace2b2575d2ab97dc7db2774b2dcc9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: purerpc-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for purerpc-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9aea134cfab6318a09578c0a6ea84cbe331f7bd1bc23d94bc614d896b120949a
MD5 6473a615677d7b52625ac63c74dc66e3
BLAKE2b-256 9936ec996ea69bb3c387e832c179f97e93a563697bf638ea18b57afa487526f2

See more details on using hashes here.

Supported by

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