aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/python/helloworld
diff options
context:
space:
mode:
authorGravatar Nathaniel Manista <nathaniel@google.com>2016-12-15 22:58:29 +0000
committerGravatar Nathaniel Manista <nathaniel@google.com>2016-12-21 21:05:19 +0000
commitc15ee83882dad131b7ff9c71e29ec9cc1663781e (patch)
treec7e7f3ab368bd2857dff25d3cd7f6a7aab4bb8ff /examples/python/helloworld
parent47f1f9e1ead610ccfc464bf3f6d2918867a0a212 (diff)
Update Python examples with fresh generated code
Diffstat (limited to 'examples/python/helloworld')
-rw-r--r--examples/python/helloworld/greeter_client.py3
-rw-r--r--examples/python/helloworld/greeter_server.py5
-rw-r--r--examples/python/helloworld/helloworld_pb2.py193
-rw-r--r--examples/python/helloworld/helloworld_pb2_grpc.py47
4 files changed, 161 insertions, 87 deletions
diff --git a/examples/python/helloworld/greeter_client.py b/examples/python/helloworld/greeter_client.py
index 44d42c102b..281a68f3c3 100644
--- a/examples/python/helloworld/greeter_client.py
+++ b/examples/python/helloworld/greeter_client.py
@@ -34,11 +34,12 @@ from __future__ import print_function
import grpc
import helloworld_pb2
+import helloworld_pb2_grpc
def run():
channel = grpc.insecure_channel('localhost:50051')
- stub = helloworld_pb2.GreeterStub(channel)
+ stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: " + response.message)
diff --git a/examples/python/helloworld/greeter_server.py b/examples/python/helloworld/greeter_server.py
index 37d8bd49cc..0afc21d243 100644
--- a/examples/python/helloworld/greeter_server.py
+++ b/examples/python/helloworld/greeter_server.py
@@ -35,11 +35,12 @@ import time
import grpc
import helloworld_pb2
+import helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
-class Greeter(helloworld_pb2.GreeterServicer):
+class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
@@ -47,7 +48,7 @@ class Greeter(helloworld_pb2.GreeterServicer):
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
- helloworld_pb2.add_GreeterServicer_to_server(Greeter(), server)
+ helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
diff --git a/examples/python/helloworld/helloworld_pb2.py b/examples/python/helloworld/helloworld_pb2.py
index 3ce33fbf2b..6665b1f687 100644
--- a/examples/python/helloworld/helloworld_pb2.py
+++ b/examples/python/helloworld/helloworld_pb2.py
@@ -107,98 +107,123 @@ _sym_db.RegisterMessage(HelloReply)
DESCRIPTOR.has_options = True
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW'))
-import grpc
-from grpc.beta import implementations as beta_implementations
-from grpc.beta import interfaces as beta_interfaces
-from grpc.framework.common import cardinality
-from grpc.framework.interfaces.face import utilities as face_utilities
+try:
+ # THESE ELEMENTS WILL BE DEPRECATED.
+ # Please use the generated *_pb2_grpc.py files instead.
+ import grpc
+ from grpc.framework.common import cardinality
+ from grpc.framework.interfaces.face import utilities as face_utilities
+ from grpc.beta import implementations as beta_implementations
+ from grpc.beta import interfaces as beta_interfaces
+
+
+ class GreeterStub(object):
+ """The greeting service definition.
+ """
+ def __init__(self, channel):
+ """Constructor.
-class GreeterStub(object):
- """The greeting service definition.
- """
+ Args:
+ channel: A grpc.Channel.
+ """
+ self.SayHello = channel.unary_unary(
+ '/helloworld.Greeter/SayHello',
+ request_serializer=HelloRequest.SerializeToString,
+ response_deserializer=HelloReply.FromString,
+ )
- def __init__(self, channel):
- """Constructor.
- Args:
- channel: A grpc.Channel.
+ class GreeterServicer(object):
+ """The greeting service definition.
"""
- self.SayHello = channel.unary_unary(
- '/helloworld.Greeter/SayHello',
- request_serializer=HelloRequest.SerializeToString,
- response_deserializer=HelloReply.FromString,
- )
-
-
-class GreeterServicer(object):
- """The greeting service definition.
- """
- def SayHello(self, request, context):
- """Sends a greeting
+ def SayHello(self, request, context):
+ """Sends a greeting
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+
+ def add_GreeterServicer_to_server(servicer, server):
+ rpc_method_handlers = {
+ 'SayHello': grpc.unary_unary_rpc_method_handler(
+ servicer.SayHello,
+ request_deserializer=HelloRequest.FromString,
+ response_serializer=HelloReply.SerializeToString,
+ ),
+ }
+ generic_handler = grpc.method_handlers_generic_handler(
+ 'helloworld.Greeter', rpc_method_handlers)
+ server.add_generic_rpc_handlers((generic_handler,))
+
+
+ class BetaGreeterServicer(object):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This class was generated
+ only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
+ """The greeting service definition.
"""
- context.set_code(grpc.StatusCode.UNIMPLEMENTED)
- context.set_details('Method not implemented!')
- raise NotImplementedError('Method not implemented!')
-
-
-def add_GreeterServicer_to_server(servicer, server):
- rpc_method_handlers = {
- 'SayHello': grpc.unary_unary_rpc_method_handler(
- servicer.SayHello,
- request_deserializer=HelloRequest.FromString,
- response_serializer=HelloReply.SerializeToString,
- ),
- }
- generic_handler = grpc.method_handlers_generic_handler(
- 'helloworld.Greeter', rpc_method_handlers)
- server.add_generic_rpc_handlers((generic_handler,))
-
-
-class BetaGreeterServicer(object):
- """The greeting service definition.
- """
- def SayHello(self, request, context):
- """Sends a greeting
- """
- context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
+ def SayHello(self, request, context):
+ """Sends a greeting
+ """
+ context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
+
+ class BetaGreeterStub(object):
+ """The Beta API is deprecated for 0.15.0 and later.
-class BetaGreeterStub(object):
- """The greeting service definition.
- """
- def SayHello(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
- """Sends a greeting
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This class was generated
+ only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
+ """The greeting service definition.
"""
- raise NotImplementedError()
- SayHello.future = None
-
-
-def beta_create_Greeter_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None):
- request_deserializers = {
- ('helloworld.Greeter', 'SayHello'): HelloRequest.FromString,
- }
- response_serializers = {
- ('helloworld.Greeter', 'SayHello'): HelloReply.SerializeToString,
- }
- method_implementations = {
- ('helloworld.Greeter', 'SayHello'): face_utilities.unary_unary_inline(servicer.SayHello),
- }
- server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout)
- return beta_implementations.server(method_implementations, options=server_options)
-
-
-def beta_create_Greeter_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None):
- request_serializers = {
- ('helloworld.Greeter', 'SayHello'): HelloRequest.SerializeToString,
- }
- response_deserializers = {
- ('helloworld.Greeter', 'SayHello'): HelloReply.FromString,
- }
- cardinalities = {
- 'SayHello': cardinality.Cardinality.UNARY_UNARY,
- }
- stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size)
- return beta_implementations.dynamic_stub(channel, 'helloworld.Greeter', cardinalities, options=stub_options)
+ def SayHello(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
+ """Sends a greeting
+ """
+ raise NotImplementedError()
+ SayHello.future = None
+
+
+ def beta_create_Greeter_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This function was
+ generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
+ request_deserializers = {
+ ('helloworld.Greeter', 'SayHello'): HelloRequest.FromString,
+ }
+ response_serializers = {
+ ('helloworld.Greeter', 'SayHello'): HelloReply.SerializeToString,
+ }
+ method_implementations = {
+ ('helloworld.Greeter', 'SayHello'): face_utilities.unary_unary_inline(servicer.SayHello),
+ }
+ server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout)
+ return beta_implementations.server(method_implementations, options=server_options)
+
+
+ def beta_create_Greeter_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This function was
+ generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
+ request_serializers = {
+ ('helloworld.Greeter', 'SayHello'): HelloRequest.SerializeToString,
+ }
+ response_deserializers = {
+ ('helloworld.Greeter', 'SayHello'): HelloReply.FromString,
+ }
+ cardinalities = {
+ 'SayHello': cardinality.Cardinality.UNARY_UNARY,
+ }
+ stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size)
+ return beta_implementations.dynamic_stub(channel, 'helloworld.Greeter', cardinalities, options=stub_options)
+except ImportError:
+ pass
# @@protoc_insertion_point(module_scope)
diff --git a/examples/python/helloworld/helloworld_pb2_grpc.py b/examples/python/helloworld/helloworld_pb2_grpc.py
new file mode 100644
index 0000000000..682dc36cd8
--- /dev/null
+++ b/examples/python/helloworld/helloworld_pb2_grpc.py
@@ -0,0 +1,47 @@
+import grpc
+from grpc.framework.common import cardinality
+from grpc.framework.interfaces.face import utilities as face_utilities
+
+import helloworld_pb2 as helloworld__pb2
+
+
+class GreeterStub(object):
+ """The greeting service definition.
+ """
+
+ def __init__(self, channel):
+ """Constructor.
+
+ Args:
+ channel: A grpc.Channel.
+ """
+ self.SayHello = channel.unary_unary(
+ '/helloworld.Greeter/SayHello',
+ request_serializer=helloworld__pb2.HelloRequest.SerializeToString,
+ response_deserializer=helloworld__pb2.HelloReply.FromString,
+ )
+
+
+class GreeterServicer(object):
+ """The greeting service definition.
+ """
+
+ def SayHello(self, request, context):
+ """Sends a greeting
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+
+def add_GreeterServicer_to_server(servicer, server):
+ rpc_method_handlers = {
+ 'SayHello': grpc.unary_unary_rpc_method_handler(
+ servicer.SayHello,
+ request_deserializer=helloworld__pb2.HelloRequest.FromString,
+ response_serializer=helloworld__pb2.HelloReply.SerializeToString,
+ ),
+ }
+ generic_handler = grpc.method_handlers_generic_handler(
+ 'helloworld.Greeter', rpc_method_handlers)
+ server.add_generic_rpc_handlers((generic_handler,))