Skip to main content

fast to code grpc in python

Project description

fast-grpc

Fast to Code gRPC in Python 3.7+

Installation

Require Python 3.7+

pip install python-fast-grpc

Quick start

  1. Run a gRPC application
from fast_grpc import BaseSchema, FastGRPC, ServicerContext, method

app = FastGRPC()

class HelloRequest(BaseSchema):
    name: str

class HelloReply(BaseSchema):
    message: str

class Greeter:
    @method("SayHello", request_model=HelloRequest, response_model=HelloReply)
    async def say_hello(self, request: HelloRequest, context: ServicerContext) -> HelloReply:
        return HelloReply(message=f"Greeter SayHello {request.name}")

app.add_service(Greeter)
# this step will generate .proto file and python gRPC code, then start a grpc server
app.run()
  1. Client invoke
import grpc
import greeter_pb2 as pb2
import greeter_pb2_grpc as pb2_grpc

channel = grpc.insecure_channel("127.0.0.1:50051")
stub = pb2_grpc.GreeterStub(channel)
response = stub.SayHello(pb2.HelloRequest(name="fastGRPC"))
print("Greeter client received: ", response)

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

python_fast_grpc-0.1.3.tar.gz (14.1 kB view hashes)

Uploaded Source

Built Distribution

python_fast_grpc-0.1.3-py3-none-any.whl (16.7 kB view hashes)

Uploaded Python 3

Supported by

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