14 """An example of compression on the client side with gRPC."""
16 from __future__
import absolute_import
17 from __future__
import division
18 from __future__
import print_function
25 from examples.protos
import helloworld_pb2
26 from examples.protos
import helloworld_pb2_grpc
28 _DESCRIPTION =
'A client capable of compression.'
29 _COMPRESSION_OPTIONS = {
30 "none": grpc.Compression.NoCompression,
31 "deflate": grpc.Compression.Deflate,
32 "gzip": grpc.Compression.Gzip,
35 _LOGGER = logging.getLogger(__name__)
38 def run_client(channel_compression, call_compression, target):
40 compression=channel_compression)
as channel:
43 compression=call_compression,
45 print(
"Response: {}".
format(response))
49 parser = argparse.ArgumentParser(description=_DESCRIPTION)
50 parser.add_argument(
'--channel_compression',
53 choices=_COMPRESSION_OPTIONS.keys(),
54 help=
'The compression method to use for the channel.')
59 choices=_COMPRESSION_OPTIONS.keys(),
60 help=
'The compression method to use for an individual call.')
61 parser.add_argument(
'--server',
62 default=
'localhost:50051',
65 help=
'The host-port pair at which to reach the server.')
66 args = parser.parse_args()
67 channel_compression = _COMPRESSION_OPTIONS[args.channel_compression]
68 call_compression = _COMPRESSION_OPTIONS[args.call_compression]
69 run_client(channel_compression, call_compression, args.server)
72 if __name__ ==
"__main__":