File: README.md

package info (click to toggle)
grpc 1.51.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,328 kB
  • sloc: cpp: 361,873; python: 72,206; ansic: 37,787; objc: 12,434; ruby: 11,521; sh: 7,652; php: 7,615; makefile: 3,481; xml: 3,246; cs: 1,836; javascript: 1,614; java: 465; pascal: 227; awk: 132
file content (58 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## Compression with gRPC Python

gRPC offers lossless compression options in order to decrease the number of bits
transferred over the wire. Three levels of compression are available:

 - `grpc.Compression.NoCompression` - No compression is applied to the payload. (default)
 - `grpc.Compression.Deflate` - The "Deflate" algorithm is applied to the payload.
 - `grpc.Compression.Gzip` - The Gzip algorithm is applied to the payload.

The default option on both clients and servers is `grpc.Compression.NoCompression`.

See [the gRPC Compression Spec](https://github.com/grpc/grpc/blob/master/doc/compression.md)
for more information.

### Client Side Compression

Compression may be set at two levels on the client side.

#### At the channel level

```python
with grpc.insecure_channel('foo.bar:1234', compression=grpc.Compression.Gzip) as channel:
    use_channel(channel)
```

#### At the call level

Setting the compression method at the call level will override any settings on
the channel level.

```python
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'),
                         compression=grpc.Compression.Deflate)
```


### Server Side Compression

Additionally, compression may be set at two levels on the server side.

#### On the entire server

```python
server = grpc.server(futures.ThreadPoolExecutor(),
                     compression=grpc.Compression.Gzip)
```

#### For an individual RPC

```python
def SayHello(self, request, context):
    context.set_response_compression(grpc.Compression.NoCompression)
    return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
```

Setting the compression method for an individual RPC will override any setting
supplied at server creation time.