hrpc/README.md

56 lines
893 B
Markdown
Raw Normal View History

2020-08-08 23:33:07 +00:00
# hrpc
2020-08-08 23:37:19 +00:00
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/hrpc/status.svg)](https://drone.autonomic.zone/hyperpy/hrpc)
2020-08-08 23:33:07 +00:00
## Simple RPC with Protobuf Services
## Install
```sh
$ pip install hrpc
```
## Example
2020-08-09 00:52:29 +00:00
> **TLDR; See the [example](./example/) directory**
2020-08-08 23:33:07 +00:00
Define an RPC service in a `schema.proto`.
```protobuf
2020-08-09 00:52:29 +00:00
syntax = "proto2";
message EchoMsg {
2020-08-08 23:33:07 +00:00
required string value = 1;
}
service Example {
2020-08-09 00:52:29 +00:00
rpc Echo (EchoMsg) returns (EchoMsg) {}
2020-08-08 23:33:07 +00:00
}
```
Then generate the services and stubs with `hrpc`.
```sh
$ pip install hrpc
$ hrpc schema.proto
```
This creates `schema_gprc.py` (services) and `schema_pb2.py` (stubs) files.
2020-08-09 00:52:29 +00:00
You can then write a async-ready server and client like so.
2020-08-08 23:33:07 +00:00
```python
# server.py
```
```python
# client.py
```
2020-08-09 00:52:29 +00:00
And run them in separate terminals to see the output.
2020-08-08 23:33:07 +00:00
```
$ python server.py # terminal 1
$ python client.py # terminal 2
```