This release is a pre-release and may not be stable for production use.
hyper-rpc
Simple RPC with Protobuf Services
Uses grpcio_tools and purerpc under the hood.
Install
$ pip install hyper-rpc
Example
TLDR; See the example directory
Define an RPC service in a greeter.proto.
syntax = "proto3";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc SayHelloGoodbye (HelloRequest) returns (stream HelloReply) {}
rpc SayHelloToMany (stream HelloRequest) returns (stream HelloReply) {}
rpc SayHelloToManyAtOnce (stream HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
Then generate the services and stubs with hyper-rpc.
$ pip install hyper-rpc
$ hrpc greeter.proto
This creates greeter_gprc.py (services) and greeter_pb2.py (stubs) files.
You can then write an async-ready server.
"""Greeter server."""
from greeter_grpc import GreeterServicer
from greeter_pb2 import HelloReply, HelloRequest
from purerpc import Server
class Greeter(GreeterServicer):
async def SayHello(self, message):
return HelloReply(message=f"Hello {message.name}")
async def SayHelloToMany(self, input_messages):
async for message in input_messages:
yield HelloReply(message=f"Hello, {message.name}")
if __name__ == "__main__":
server = Server(50055)
server.add_service(Greeter().service)
server.serve(backend="trio")
And a client.
"""Greeter client."""
import anyio
import purerpc
from greeter_grpc import GreeterStub
from greeter_pb2 import HelloReply, HelloRequest
async def gen():
for i in range(5):
yield HelloRequest(name=str(i))
async def main():
async with purerpc.insecure_channel("localhost", 50055) as channel:
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__":
anyio.run(main, backend="trio")
And run them in separate terminals to see the output.
$ python server.py # terminal 1
$ python client.py # terminal 2
Output:
Hello, World
Hello, 0
Hello, 1
Hello, 2
Hello, 3
Hello, 4
Go forth and Remote Procedure Call.
Metadata
Release files for hyper-rpc 0.0.1a4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| hyper-rpc-0.0.1a4.tar.gz | 15.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hyper_rpc-0.0.1a4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.8 kB
Release files / hyper-rpc-0.0.1a4.tar.gz
| Download URL | hyper-rpc-0.0.1a4.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5434d8711fd590ecd5b902171517661d8ca6302f16c9962f7d758841936ac97
|
|
BLAKE2b-256 checksum How to use checksums |
a5f256dd97c7c10dbdc7bce5939bbd59ceb4985f0b4a94a260a1a5fd229066a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.0 Linux/4.9.0-13-amd64
|
Release files / hyper_rpc-0.0.1a4-py3-none-any.whl
| Download URL | hyper_rpc-0.0.1a4-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37dcb611dee7536e11c62560df85bda57a4f0998e0be013bf7ad08c26865fbcb
|
|
BLAKE2b-256 checksum How to use checksums |
f9c783157fd2de0da54af75d267a482996d53358e2b893c0f0a3b91093b088e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.0 Linux/4.9.0-13-amd64
|
Security for hyper-rpc 0.0.1a4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.