Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2020 12:13
What would you like to do?
import grpc
import unary.unary_pb2_grpc as pb2_grpc
import unary.unary_pb2 as pb2
class UnaryClient(object):
Client for gRPC functionality
def __init__(self): = 'localhost'
self.server_port = 50051
# instantiate a channel = grpc.insecure_channel(
'{}:{}'.format(, self.server_port))
# bind the client and the server
self.stub = pb2_grpc.UnaryStub(
def get_url(self, message):
Client function to call the rpc for GetServerResponse
message = pb2.Message(message=message)
return self.stub.GetServerResponse(message)
if __name__ == '__main__':
client = UnaryClient()
result = client.get_url(message="Hello Server you there?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment