Skip to content
/ yQL Public

protobuf powered RPC but REST instead sockets, creates client & server stubs. Used in production at NimbleBox.

License

Notifications You must be signed in to change notification settings

yashbonde/yQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yQL

Compile Protobuf to fastAPI.

Light weight (5.68Kb) embed-able library. Used in production at NimbleBox.

Usage

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 + "!")

Installation

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

About

protobuf powered RPC but REST instead sockets, creates client & server stubs. Used in production at NimbleBox.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published