Compression

Zstd and gzip content-encoding with zero external dependencies

1 min read 234 words

Overview

Pounce negotiates content-encoding automatically based on the client'sAccept-Encodingheader. Priority order:

  1. zstd — Best compression ratio, lowest CPU cost (Python 3.14 stdlib, PEP 784)
  2. gzip — Universal browser support (stdlibzlib)
  3. identity — No compression (fallback)

All compression uses Python standard library modules — zero external dependencies.

Configuration

Compression is enabled by default:

# Disabled (compression is enabled by default)
pounce myapp:app --no-compression

Programmatically:

import pounce

pounce.run(
    "myapp:app",
    compression=True,
    compression_min_size=500,  # bytes
)

Minimum Size

Responses smaller thancompression_min_size(default: 500 bytes) are sent uncompressed. Compressing tiny responses adds CPU cost without meaningful size reduction.

Zstd (PEP 784)

Python 3.14 includescompression.zstdin the standard library. Zstd provides:

  • Better ratios than gzip at similar speeds
  • Lower CPU cost than gzip at similar ratios
  • Streaming mode — Pounce compresses response chunks as they're sent

Modern browsers (Chrome, Firefox, Safari) supportzstdcontent-encoding.

Skipped Responses

Compression is automatically skipped for:

  • SSE responsestext/event-stream(streaming requires unbuffered delivery)
  • HEAD requests — No response body to compress
  • Bodyless status codes — 1xx, 204, 304 responses
  • Responses belowcompression_min_size — Default: 500 bytes

Note

WebSocket compression uses a separate system (permessage-deflate via thewebsocket_compressionconfig option) and is not related to content-encoding compression.

See Also