Giter VIP home page Giter VIP logo

pygrpc's Introduction

pygrpc

pygrpc 0.2.0

Released: Feb-10-2015

Overview

pygrpc is a Python module that provides a high-level client connection object to instantiate Google Remote Procedure Calls (gRPCs).

Examples

By default, the Google Protocol Buffer compiler generates client and server code.

The following example is a code snippet provided by Google that creates a helloworld.Greeter stub object and invokes the SayHello method. The SayHello method takes a serializer class as its first argument (helloworld_pb2.HelloRequest):

"""The Python implementation of the GRPC helloworld.Greeter client."""

from grpc.beta import implementations

import helloworld_pb2

_TIMEOUT_SECONDS = 10

channel = implementations.insecure_channel('localhost', 50051)
stub = helloworld_pb2.beta_create_Greeter_stub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS)
print "Greeter client received: " + response.message

The following example demonstrates the same request using pygrpc:

from pygrpc import Client

client = Client('localhost', 50051)
# This loads the generated Google Protocol Buffer module.
client.load('helloworld_pb2')
response = client.request('SayHello', name='you')
print "Greeter client received: " + response.message

Both examples would output: Greeter client received: Hello, you!.

Differences

The pygrpc client only requires the request method to be called for issuing gRPC requests.

pygrpc.Client

client.request(request, *args, **kwargs)

Return a simple RPC response or a streaming RPC response. This is known as the cardinality of the gRPC request/response.

Type: str

Parameters: request - the name of the RPC request defined in the .proto file.

Return type: Reply object defined in the .proto file.

Returns: Either a simple RPC response or a streaming RPC response.

pygrpc's People

Contributors

rightlag avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.