├── __pycache__ ├── customer_pb2.cpython-35.pyc └── customer_pb2_grpc.cpython-35.pyc ├── README.md ├── server.py ├── protocol └── customer.proto ├── client.py ├── customer_pb2_grpc.py └── customer_pb2.py /__pycache__/customer_pb2.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratos/grpc_helloworld/master/__pycache__/customer_pb2.cpython-35.pyc -------------------------------------------------------------------------------- /__pycache__/customer_pb2_grpc.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratos/grpc_helloworld/master/__pycache__/customer_pb2_grpc.cpython-35.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grpc_helloworld 2 | ### Test repository to understand gRPC and protobuf 3 | (_NOTE: This is not a full fledged working example, the POST data equivalent works. Data Querying-One related to Streaming hasn't been implemented properly and may not be updated further. This project was just an exercise to understand protobuf and grpc._) 4 | 5 | Command to create `_pb2.py` files: 6 | ``` 7 | python -m grpc_tools.protoc -I./protocol --python_out=. --grpc_python_out=. ./protocol/customer.proto 8 | ``` 9 | 10 | Run the commands: 11 | 12 | - Run the server: 13 | * `python server.py` 14 | - Run the client: 15 | * `python client.py` 16 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | from concurrent import futures 2 | import time 3 | import grpc 4 | import customer_pb2 5 | import customer_pb2_grpc 6 | 7 | 8 | _ONE_DAY_IN_SECONDS = 60 * 60 * 24 9 | 10 | 11 | class Customers(customer_pb2.CustomerServicer): 12 | def CreateCustomer(self, request, context): 13 | print ("The recieved message was {}".format(request)) 14 | 15 | return customer_pb2.CustomerResponse(id = request.id, 16 | success = True) 17 | 18 | def GetCustomers(self, request, context): 19 | print ("The recieved message for PartI was {}".format(request)) 20 | 21 | searchstr = request.keyword 22 | 23 | print ("The keyword is {}".format(searchstr)) 24 | 25 | # if (searchstr == ) 26 | #customer_pb2.CustomerRequest() 27 | 28 | 29 | def serve(): 30 | server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) 31 | customer_pb2.add_CustomerServicer_to_server(Customers(), server) 32 | 33 | server.add_insecure_port('[::]:50052') 34 | server.start() 35 | 36 | print ("-------------------The Server has started-------------------------") 37 | try: 38 | while True: 39 | time.sleep(_ONE_DAY_IN_SECONDS) 40 | print ("-------------------The Server will continue-------------------------") 41 | except KeyboardInterrupt: 42 | server.stop(0) 43 | print ("-------------------The Server has stopped-------------------------") 44 | 45 | 46 | if __name__ == '__main__': 47 | serve() -------------------------------------------------------------------------------- /protocol/customer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package customer; 3 | 4 | //Customer service definition 5 | service Customer { 6 | //Get all customers with a filter - A server-client streaming RPC 7 | //A response-streaming RPC where the client sends a request to the server and gets a stream to read a 8 | //sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 9 | 10 | // clientside querying(?) 11 | rpc GetCustomers(CustomerFilter) returns (stream CustomerRequest){} 12 | 13 | //Create a new customer - A simple RPC where the client sends a request to the server using the stub and 14 | // waits for a response to come back, just like a normal function call. 15 | 16 | // serverside (?) 17 | rpc CreateCustomer(CustomerRequest) returns (CustomerResponse){} 18 | } 19 | 20 | 21 | //Request message for new customer 22 | message CustomerRequest{ 23 | int32 id = 1; 24 | string firstName = 2; 25 | string lastName = 3; 26 | string email = 4; 27 | string phone = 5; 28 | 29 | message Address{ 30 | int32 flatno = 1; 31 | string building = 2; 32 | string locality = 3; 33 | string city = 4; 34 | string country = 5; 35 | bool isShippingAddress = 6; 36 | } 37 | 38 | repeated Address addresses = 6; 39 | } 40 | 41 | message CustomerResponse{ 42 | int32 id = 1; 43 | bool success = 2; 44 | } 45 | 46 | message CustomerFilter{ 47 | string keyword = 1; 48 | } -------------------------------------------------------------------------------- /client.py: -------------------------------------------------------------------------------- 1 | import grpc 2 | import random 3 | import customer_pb2 4 | import customer_pb2_grpc 5 | 6 | 7 | def create_customer(stub): 8 | print ("-----------Creating Customer-----------") 9 | 10 | try: 11 | customer = customer_pb2.CustomerRequest() 12 | addresses = customer.addresses.add() 13 | 14 | # Asserting that the length of address would be 1 15 | #assert len(addresses) == 1 16 | 17 | customer.id = round(random.random()*100) 18 | customer.firstName = input("Enter your first name: ") 19 | customer.lastName = input("Enter your last name: ") 20 | customer.email = input("Enter your emaid-id: ") 21 | customer.phone = input("Enter your phone number: ") 22 | addresses.flatno = int(input("Enter your flat-no: ")) 23 | addresses.building = input("Enter your building: ") 24 | addresses.locality = input("Enter your locality: ") 25 | addresses.city = input("Enter your city: ") 26 | addresses.country = input("Enter your country: ") 27 | addresses.isShippingAddress = bool(input("Is this your permanent Shipping Address?: ")) 28 | #customer.addresses.MergeFrom(addresses) 29 | customer = stub.CreateCustomer(customer) 30 | 31 | print (customer) 32 | print ("----Done----") 33 | 34 | except Exception as e: 35 | print ("Encountered an exception: {}".format(str(e))) 36 | 37 | def get_data(stub, filter): 38 | print ("Retrieving data . . .") 39 | 40 | try: 41 | customerdb = customer_pb2.CustomerFilter() 42 | 43 | customerdb.keyword = filter 44 | 45 | data = stub.GetCustomers(customerdb) 46 | 47 | for datum in data: 48 | print ("The data point queried is : ") 49 | 50 | print ("Data retrieved successfully.") 51 | 52 | except Exception as e: 53 | print ("Encountered an exception: {}".format(str(e))) 54 | 55 | def run(): 56 | channel = grpc.insecure_channel('localhost:50052') 57 | stub = customer_pb2_grpc.CustomerStub(channel) 58 | 59 | create_customer(stub) 60 | 61 | filter = input("Filter to query the database: ") 62 | #get_data(stub, filter) 63 | 64 | if __name__=="__main__": 65 | run() -------------------------------------------------------------------------------- /customer_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | from grpc.framework.common import cardinality 4 | from grpc.framework.interfaces.face import utilities as face_utilities 5 | 6 | import customer_pb2 as customer__pb2 7 | 8 | 9 | class CustomerStub(object): 10 | """Customer service definition 11 | Get all customers with a filter - A server-client streaming RPC 12 | A response-streaming RPC where the client sends a request to the server and gets a stream to read a 13 | sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 14 | """ 15 | 16 | def __init__(self, channel): 17 | """Constructor. 18 | 19 | Args: 20 | channel: A grpc.Channel. 21 | """ 22 | self.GetCustomers = channel.unary_stream( 23 | '/customer.Customer/GetCustomers', 24 | request_serializer=customer__pb2.CustomerFilter.SerializeToString, 25 | response_deserializer=customer__pb2.CustomerRequest.FromString, 26 | ) 27 | self.CreateCustomer = channel.unary_unary( 28 | '/customer.Customer/CreateCustomer', 29 | request_serializer=customer__pb2.CustomerRequest.SerializeToString, 30 | response_deserializer=customer__pb2.CustomerResponse.FromString, 31 | ) 32 | 33 | 34 | class CustomerServicer(object): 35 | """Customer service definition 36 | Get all customers with a filter - A server-client streaming RPC 37 | A response-streaming RPC where the client sends a request to the server and gets a stream to read a 38 | sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 39 | """ 40 | 41 | def GetCustomers(self, request, context): 42 | """clientside querying(?) 43 | """ 44 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 45 | context.set_details('Method not implemented!') 46 | raise NotImplementedError('Method not implemented!') 47 | 48 | def CreateCustomer(self, request, context): 49 | """Create a new customer - A simple RPC where the client sends a request to the server using the stub and 50 | waits for a response to come back, just like a normal function call. 51 | 52 | serverside (?) 53 | """ 54 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 55 | context.set_details('Method not implemented!') 56 | raise NotImplementedError('Method not implemented!') 57 | 58 | 59 | def add_CustomerServicer_to_server(servicer, server): 60 | rpc_method_handlers = { 61 | 'GetCustomers': grpc.unary_stream_rpc_method_handler( 62 | servicer.GetCustomers, 63 | request_deserializer=customer__pb2.CustomerFilter.FromString, 64 | response_serializer=customer__pb2.CustomerRequest.SerializeToString, 65 | ), 66 | 'CreateCustomer': grpc.unary_unary_rpc_method_handler( 67 | servicer.CreateCustomer, 68 | request_deserializer=customer__pb2.CustomerRequest.FromString, 69 | response_serializer=customer__pb2.CustomerResponse.SerializeToString, 70 | ), 71 | } 72 | generic_handler = grpc.method_handlers_generic_handler( 73 | 'customer.Customer', rpc_method_handlers) 74 | server.add_generic_rpc_handlers((generic_handler,)) 75 | -------------------------------------------------------------------------------- /customer_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: customer.proto 3 | 4 | import sys 5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) 6 | from google.protobuf import descriptor as _descriptor 7 | from google.protobuf import message as _message 8 | from google.protobuf import reflection as _reflection 9 | from google.protobuf import symbol_database as _symbol_database 10 | from google.protobuf import descriptor_pb2 11 | # @@protoc_insertion_point(imports) 12 | 13 | _sym_db = _symbol_database.Default() 14 | 15 | 16 | 17 | 18 | DESCRIPTOR = _descriptor.FileDescriptor( 19 | name='customer.proto', 20 | package='customer', 21 | syntax='proto3', 22 | serialized_pb=_b('\n\x0e\x63ustomer.proto\x12\x08\x63ustomer\"\x8f\x02\n\x0f\x43ustomerRequest\x12\n\n\x02id\x18\x01 \x01(\x05\x12\x11\n\tfirstName\x18\x02 \x01(\t\x12\x10\n\x08lastName\x18\x03 \x01(\t\x12\r\n\x05\x65mail\x18\x04 \x01(\t\x12\r\n\x05phone\x18\x05 \x01(\t\x12\x34\n\taddresses\x18\x06 \x03(\x0b\x32!.customer.CustomerRequest.Address\x1aw\n\x07\x41\x64\x64ress\x12\x0e\n\x06\x66latno\x18\x01 \x01(\x05\x12\x10\n\x08\x62uilding\x18\x02 \x01(\t\x12\x10\n\x08locality\x18\x03 \x01(\t\x12\x0c\n\x04\x63ity\x18\x04 \x01(\t\x12\x0f\n\x07\x63ountry\x18\x05 \x01(\t\x12\x19\n\x11isShippingAddress\x18\x06 \x01(\x08\"/\n\x10\x43ustomerResponse\x12\n\n\x02id\x18\x01 \x01(\x05\x12\x0f\n\x07success\x18\x02 \x01(\x08\"!\n\x0e\x43ustomerFilter\x12\x0f\n\x07keyword\x18\x01 \x01(\t2\x9e\x01\n\x08\x43ustomer\x12G\n\x0cGetCustomers\x12\x18.customer.CustomerFilter\x1a\x19.customer.CustomerRequest\"\x00\x30\x01\x12I\n\x0e\x43reateCustomer\x12\x19.customer.CustomerRequest\x1a\x1a.customer.CustomerResponse\"\x00\x62\x06proto3') 23 | ) 24 | _sym_db.RegisterFileDescriptor(DESCRIPTOR) 25 | 26 | 27 | 28 | 29 | _CUSTOMERREQUEST_ADDRESS = _descriptor.Descriptor( 30 | name='Address', 31 | full_name='customer.CustomerRequest.Address', 32 | filename=None, 33 | file=DESCRIPTOR, 34 | containing_type=None, 35 | fields=[ 36 | _descriptor.FieldDescriptor( 37 | name='flatno', full_name='customer.CustomerRequest.Address.flatno', index=0, 38 | number=1, type=5, cpp_type=1, label=1, 39 | has_default_value=False, default_value=0, 40 | message_type=None, enum_type=None, containing_type=None, 41 | is_extension=False, extension_scope=None, 42 | options=None), 43 | _descriptor.FieldDescriptor( 44 | name='building', full_name='customer.CustomerRequest.Address.building', index=1, 45 | number=2, type=9, cpp_type=9, label=1, 46 | has_default_value=False, default_value=_b("").decode('utf-8'), 47 | message_type=None, enum_type=None, containing_type=None, 48 | is_extension=False, extension_scope=None, 49 | options=None), 50 | _descriptor.FieldDescriptor( 51 | name='locality', full_name='customer.CustomerRequest.Address.locality', index=2, 52 | number=3, type=9, cpp_type=9, label=1, 53 | has_default_value=False, default_value=_b("").decode('utf-8'), 54 | message_type=None, enum_type=None, containing_type=None, 55 | is_extension=False, extension_scope=None, 56 | options=None), 57 | _descriptor.FieldDescriptor( 58 | name='city', full_name='customer.CustomerRequest.Address.city', index=3, 59 | number=4, type=9, cpp_type=9, label=1, 60 | has_default_value=False, default_value=_b("").decode('utf-8'), 61 | message_type=None, enum_type=None, containing_type=None, 62 | is_extension=False, extension_scope=None, 63 | options=None), 64 | _descriptor.FieldDescriptor( 65 | name='country', full_name='customer.CustomerRequest.Address.country', index=4, 66 | number=5, type=9, cpp_type=9, label=1, 67 | has_default_value=False, default_value=_b("").decode('utf-8'), 68 | message_type=None, enum_type=None, containing_type=None, 69 | is_extension=False, extension_scope=None, 70 | options=None), 71 | _descriptor.FieldDescriptor( 72 | name='isShippingAddress', full_name='customer.CustomerRequest.Address.isShippingAddress', index=5, 73 | number=6, type=8, cpp_type=7, label=1, 74 | has_default_value=False, default_value=False, 75 | message_type=None, enum_type=None, containing_type=None, 76 | is_extension=False, extension_scope=None, 77 | options=None), 78 | ], 79 | extensions=[ 80 | ], 81 | nested_types=[], 82 | enum_types=[ 83 | ], 84 | options=None, 85 | is_extendable=False, 86 | syntax='proto3', 87 | extension_ranges=[], 88 | oneofs=[ 89 | ], 90 | serialized_start=181, 91 | serialized_end=300, 92 | ) 93 | 94 | _CUSTOMERREQUEST = _descriptor.Descriptor( 95 | name='CustomerRequest', 96 | full_name='customer.CustomerRequest', 97 | filename=None, 98 | file=DESCRIPTOR, 99 | containing_type=None, 100 | fields=[ 101 | _descriptor.FieldDescriptor( 102 | name='id', full_name='customer.CustomerRequest.id', index=0, 103 | number=1, type=5, cpp_type=1, label=1, 104 | has_default_value=False, default_value=0, 105 | message_type=None, enum_type=None, containing_type=None, 106 | is_extension=False, extension_scope=None, 107 | options=None), 108 | _descriptor.FieldDescriptor( 109 | name='firstName', full_name='customer.CustomerRequest.firstName', index=1, 110 | number=2, type=9, cpp_type=9, label=1, 111 | has_default_value=False, default_value=_b("").decode('utf-8'), 112 | message_type=None, enum_type=None, containing_type=None, 113 | is_extension=False, extension_scope=None, 114 | options=None), 115 | _descriptor.FieldDescriptor( 116 | name='lastName', full_name='customer.CustomerRequest.lastName', index=2, 117 | number=3, type=9, cpp_type=9, label=1, 118 | has_default_value=False, default_value=_b("").decode('utf-8'), 119 | message_type=None, enum_type=None, containing_type=None, 120 | is_extension=False, extension_scope=None, 121 | options=None), 122 | _descriptor.FieldDescriptor( 123 | name='email', full_name='customer.CustomerRequest.email', index=3, 124 | number=4, type=9, cpp_type=9, label=1, 125 | has_default_value=False, default_value=_b("").decode('utf-8'), 126 | message_type=None, enum_type=None, containing_type=None, 127 | is_extension=False, extension_scope=None, 128 | options=None), 129 | _descriptor.FieldDescriptor( 130 | name='phone', full_name='customer.CustomerRequest.phone', index=4, 131 | number=5, type=9, cpp_type=9, label=1, 132 | has_default_value=False, default_value=_b("").decode('utf-8'), 133 | message_type=None, enum_type=None, containing_type=None, 134 | is_extension=False, extension_scope=None, 135 | options=None), 136 | _descriptor.FieldDescriptor( 137 | name='addresses', full_name='customer.CustomerRequest.addresses', index=5, 138 | number=6, type=11, cpp_type=10, label=3, 139 | has_default_value=False, default_value=[], 140 | message_type=None, enum_type=None, containing_type=None, 141 | is_extension=False, extension_scope=None, 142 | options=None), 143 | ], 144 | extensions=[ 145 | ], 146 | nested_types=[_CUSTOMERREQUEST_ADDRESS, ], 147 | enum_types=[ 148 | ], 149 | options=None, 150 | is_extendable=False, 151 | syntax='proto3', 152 | extension_ranges=[], 153 | oneofs=[ 154 | ], 155 | serialized_start=29, 156 | serialized_end=300, 157 | ) 158 | 159 | 160 | _CUSTOMERRESPONSE = _descriptor.Descriptor( 161 | name='CustomerResponse', 162 | full_name='customer.CustomerResponse', 163 | filename=None, 164 | file=DESCRIPTOR, 165 | containing_type=None, 166 | fields=[ 167 | _descriptor.FieldDescriptor( 168 | name='id', full_name='customer.CustomerResponse.id', index=0, 169 | number=1, type=5, cpp_type=1, label=1, 170 | has_default_value=False, default_value=0, 171 | message_type=None, enum_type=None, containing_type=None, 172 | is_extension=False, extension_scope=None, 173 | options=None), 174 | _descriptor.FieldDescriptor( 175 | name='success', full_name='customer.CustomerResponse.success', index=1, 176 | number=2, type=8, cpp_type=7, label=1, 177 | has_default_value=False, default_value=False, 178 | message_type=None, enum_type=None, containing_type=None, 179 | is_extension=False, extension_scope=None, 180 | options=None), 181 | ], 182 | extensions=[ 183 | ], 184 | nested_types=[], 185 | enum_types=[ 186 | ], 187 | options=None, 188 | is_extendable=False, 189 | syntax='proto3', 190 | extension_ranges=[], 191 | oneofs=[ 192 | ], 193 | serialized_start=302, 194 | serialized_end=349, 195 | ) 196 | 197 | 198 | _CUSTOMERFILTER = _descriptor.Descriptor( 199 | name='CustomerFilter', 200 | full_name='customer.CustomerFilter', 201 | filename=None, 202 | file=DESCRIPTOR, 203 | containing_type=None, 204 | fields=[ 205 | _descriptor.FieldDescriptor( 206 | name='keyword', full_name='customer.CustomerFilter.keyword', index=0, 207 | number=1, type=9, cpp_type=9, label=1, 208 | has_default_value=False, default_value=_b("").decode('utf-8'), 209 | message_type=None, enum_type=None, containing_type=None, 210 | is_extension=False, extension_scope=None, 211 | options=None), 212 | ], 213 | extensions=[ 214 | ], 215 | nested_types=[], 216 | enum_types=[ 217 | ], 218 | options=None, 219 | is_extendable=False, 220 | syntax='proto3', 221 | extension_ranges=[], 222 | oneofs=[ 223 | ], 224 | serialized_start=351, 225 | serialized_end=384, 226 | ) 227 | 228 | _CUSTOMERREQUEST_ADDRESS.containing_type = _CUSTOMERREQUEST 229 | _CUSTOMERREQUEST.fields_by_name['addresses'].message_type = _CUSTOMERREQUEST_ADDRESS 230 | DESCRIPTOR.message_types_by_name['CustomerRequest'] = _CUSTOMERREQUEST 231 | DESCRIPTOR.message_types_by_name['CustomerResponse'] = _CUSTOMERRESPONSE 232 | DESCRIPTOR.message_types_by_name['CustomerFilter'] = _CUSTOMERFILTER 233 | 234 | CustomerRequest = _reflection.GeneratedProtocolMessageType('CustomerRequest', (_message.Message,), dict( 235 | 236 | Address = _reflection.GeneratedProtocolMessageType('Address', (_message.Message,), dict( 237 | DESCRIPTOR = _CUSTOMERREQUEST_ADDRESS, 238 | __module__ = 'customer_pb2' 239 | # @@protoc_insertion_point(class_scope:customer.CustomerRequest.Address) 240 | )) 241 | , 242 | DESCRIPTOR = _CUSTOMERREQUEST, 243 | __module__ = 'customer_pb2' 244 | # @@protoc_insertion_point(class_scope:customer.CustomerRequest) 245 | )) 246 | _sym_db.RegisterMessage(CustomerRequest) 247 | _sym_db.RegisterMessage(CustomerRequest.Address) 248 | 249 | CustomerResponse = _reflection.GeneratedProtocolMessageType('CustomerResponse', (_message.Message,), dict( 250 | DESCRIPTOR = _CUSTOMERRESPONSE, 251 | __module__ = 'customer_pb2' 252 | # @@protoc_insertion_point(class_scope:customer.CustomerResponse) 253 | )) 254 | _sym_db.RegisterMessage(CustomerResponse) 255 | 256 | CustomerFilter = _reflection.GeneratedProtocolMessageType('CustomerFilter', (_message.Message,), dict( 257 | DESCRIPTOR = _CUSTOMERFILTER, 258 | __module__ = 'customer_pb2' 259 | # @@protoc_insertion_point(class_scope:customer.CustomerFilter) 260 | )) 261 | _sym_db.RegisterMessage(CustomerFilter) 262 | 263 | 264 | try: 265 | # THESE ELEMENTS WILL BE DEPRECATED. 266 | # Please use the generated *_pb2_grpc.py files instead. 267 | import grpc 268 | from grpc.framework.common import cardinality 269 | from grpc.framework.interfaces.face import utilities as face_utilities 270 | from grpc.beta import implementations as beta_implementations 271 | from grpc.beta import interfaces as beta_interfaces 272 | 273 | 274 | class CustomerStub(object): 275 | """Customer service definition 276 | Get all customers with a filter - A server-client streaming RPC 277 | A response-streaming RPC where the client sends a request to the server and gets a stream to read a 278 | sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 279 | """ 280 | 281 | def __init__(self, channel): 282 | """Constructor. 283 | 284 | Args: 285 | channel: A grpc.Channel. 286 | """ 287 | self.GetCustomers = channel.unary_stream( 288 | '/customer.Customer/GetCustomers', 289 | request_serializer=CustomerFilter.SerializeToString, 290 | response_deserializer=CustomerRequest.FromString, 291 | ) 292 | self.CreateCustomer = channel.unary_unary( 293 | '/customer.Customer/CreateCustomer', 294 | request_serializer=CustomerRequest.SerializeToString, 295 | response_deserializer=CustomerResponse.FromString, 296 | ) 297 | 298 | 299 | class CustomerServicer(object): 300 | """Customer service definition 301 | Get all customers with a filter - A server-client streaming RPC 302 | A response-streaming RPC where the client sends a request to the server and gets a stream to read a 303 | sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 304 | """ 305 | 306 | def GetCustomers(self, request, context): 307 | """clientside querying(?) 308 | """ 309 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 310 | context.set_details('Method not implemented!') 311 | raise NotImplementedError('Method not implemented!') 312 | 313 | def CreateCustomer(self, request, context): 314 | """Create a new customer - A simple RPC where the client sends a request to the server using the stub and 315 | waits for a response to come back, just like a normal function call. 316 | 317 | serverside (?) 318 | """ 319 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 320 | context.set_details('Method not implemented!') 321 | raise NotImplementedError('Method not implemented!') 322 | 323 | 324 | def add_CustomerServicer_to_server(servicer, server): 325 | rpc_method_handlers = { 326 | 'GetCustomers': grpc.unary_stream_rpc_method_handler( 327 | servicer.GetCustomers, 328 | request_deserializer=CustomerFilter.FromString, 329 | response_serializer=CustomerRequest.SerializeToString, 330 | ), 331 | 'CreateCustomer': grpc.unary_unary_rpc_method_handler( 332 | servicer.CreateCustomer, 333 | request_deserializer=CustomerRequest.FromString, 334 | response_serializer=CustomerResponse.SerializeToString, 335 | ), 336 | } 337 | generic_handler = grpc.method_handlers_generic_handler( 338 | 'customer.Customer', rpc_method_handlers) 339 | server.add_generic_rpc_handlers((generic_handler,)) 340 | 341 | 342 | class BetaCustomerServicer(object): 343 | """The Beta API is deprecated for 0.15.0 and later. 344 | 345 | It is recommended to use the GA API (classes and functions in this 346 | file not marked beta) for all further purposes. This class was generated 347 | only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" 348 | """Customer service definition 349 | Get all customers with a filter - A server-client streaming RPC 350 | A response-streaming RPC where the client sends a request to the server and gets a stream to read a 351 | sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 352 | """ 353 | def GetCustomers(self, request, context): 354 | """clientside querying(?) 355 | """ 356 | context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) 357 | def CreateCustomer(self, request, context): 358 | """Create a new customer - A simple RPC where the client sends a request to the server using the stub and 359 | waits for a response to come back, just like a normal function call. 360 | 361 | serverside (?) 362 | """ 363 | context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) 364 | 365 | 366 | class BetaCustomerStub(object): 367 | """The Beta API is deprecated for 0.15.0 and later. 368 | 369 | It is recommended to use the GA API (classes and functions in this 370 | file not marked beta) for all further purposes. This class was generated 371 | only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" 372 | """Customer service definition 373 | Get all customers with a filter - A server-client streaming RPC 374 | A response-streaming RPC where the client sends a request to the server and gets a stream to read a 375 | sequence of messages back. The client reads from the returned stream until there are no more messages. As //you can see in the example, you specify a response-streaming method by placing the stream keyword before //the response type. 376 | """ 377 | def GetCustomers(self, request, timeout, metadata=None, with_call=False, protocol_options=None): 378 | """clientside querying(?) 379 | """ 380 | raise NotImplementedError() 381 | def CreateCustomer(self, request, timeout, metadata=None, with_call=False, protocol_options=None): 382 | """Create a new customer - A simple RPC where the client sends a request to the server using the stub and 383 | waits for a response to come back, just like a normal function call. 384 | 385 | serverside (?) 386 | """ 387 | raise NotImplementedError() 388 | CreateCustomer.future = None 389 | 390 | 391 | def beta_create_Customer_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): 392 | """The Beta API is deprecated for 0.15.0 and later. 393 | 394 | It is recommended to use the GA API (classes and functions in this 395 | file not marked beta) for all further purposes. This function was 396 | generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" 397 | request_deserializers = { 398 | ('customer.Customer', 'CreateCustomer'): CustomerRequest.FromString, 399 | ('customer.Customer', 'GetCustomers'): CustomerFilter.FromString, 400 | } 401 | response_serializers = { 402 | ('customer.Customer', 'CreateCustomer'): CustomerResponse.SerializeToString, 403 | ('customer.Customer', 'GetCustomers'): CustomerRequest.SerializeToString, 404 | } 405 | method_implementations = { 406 | ('customer.Customer', 'CreateCustomer'): face_utilities.unary_unary_inline(servicer.CreateCustomer), 407 | ('customer.Customer', 'GetCustomers'): face_utilities.unary_stream_inline(servicer.GetCustomers), 408 | } 409 | 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) 410 | return beta_implementations.server(method_implementations, options=server_options) 411 | 412 | 413 | def beta_create_Customer_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): 414 | """The Beta API is deprecated for 0.15.0 and later. 415 | 416 | It is recommended to use the GA API (classes and functions in this 417 | file not marked beta) for all further purposes. This function was 418 | generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" 419 | request_serializers = { 420 | ('customer.Customer', 'CreateCustomer'): CustomerRequest.SerializeToString, 421 | ('customer.Customer', 'GetCustomers'): CustomerFilter.SerializeToString, 422 | } 423 | response_deserializers = { 424 | ('customer.Customer', 'CreateCustomer'): CustomerResponse.FromString, 425 | ('customer.Customer', 'GetCustomers'): CustomerRequest.FromString, 426 | } 427 | cardinalities = { 428 | 'CreateCustomer': cardinality.Cardinality.UNARY_UNARY, 429 | 'GetCustomers': cardinality.Cardinality.UNARY_STREAM, 430 | } 431 | 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) 432 | return beta_implementations.dynamic_stub(channel, 'customer.Customer', cardinalities, options=stub_options) 433 | except ImportError: 434 | pass 435 | # @@protoc_insertion_point(module_scope) 436 | --------------------------------------------------------------------------------