Light weight (5.68Kb) embed-able library. Used in production at NimbleBox.
Install protoc
on your machine:
protoc --python_out=./ --mypy_out=./ --plugin=protoc-gen-custom=./yql/main.py ./examples/helloworld/helloworld.proto
This will create the following files, by default writes in the same folder that the proto is present in:
./
├── helloworld.proto
├── helloworld_client.py
├── helloworld_pb2.py
├── helloworld_pb2.pyi
├── helloworld_server.py
├── server.py
└── yql/
├── __init__.py
├── common.py
├── rest_pb2.py
└── rest_pb2.pyi
Import {name}_client
in your application:
from helloworld_client import GreeterStub, HelloRequest
greeter = GreeterStub("http://127.0.0.1:8000") # define the endpoint
reply = greeter.SayHello(HelloRequest(name = "Pankaj")) # call it by passing protobufs
print(reply.message)
And implement the server functions in {name}_server.py
:
class Greeter_Servicer(object):
def SayHello(_helloworld_HelloRequest: HelloRequest) -> HelloReply:
return HelloReply(message = "Hi " + _helloworld_HelloRequest.name + "!")
Since it is used to generate embeddable folders there is no point to make it indexed on pipy, instead use this manually.
git clone https://github.com/yashbonde/yQL
cd yQL
pip install -e . # make an editable install, play with it
# to regenerate yql/rest_pb2.pyi
protoc --python_out=./ --mypy_out=./ ./yql/assets/rest.proto && mv ./yql/assets/*.py* ./yql