Classes
Compressor
4
▼
Contract for content encoders.
Compressor
4
▼
Contract for content encoders.
Methods
encoding
0
str
▼
The Content-Encoding value for this compressor (e.g., 'gzip').
property
encoding
0
str
▼
def encoding(self) -> str
Returns
str
compress
1
bytes
▼
Compress a chunk of data.
compress
1
bytes
▼
def compress(self, data: bytes) -> bytes
Parameters
| Name | Type | Description |
|---|---|---|
data |
— |
Input bytes to compress. |
Returns
bytes
Compressed bytes (may be empty if buffering internally).
flush
0
bytes
▼
Flush any buffered compressed data and finalize the stream.
After calling flus…
flush
0
bytes
▼
def flush(self) -> bytes
Flush any buffered compressed data and finalize the stream.
After calling flush(), the compressor should not be used again.
Returns
bytes
Final compressed bytes.
sync_flush
0
bytes
▼
Force buffered data out without finalizing the stream.
Used for streaming resp…
sync_flush
0
bytes
▼
def sync_flush(self) -> bytes
Force buffered data out without finalizing the stream.
Used for streaming responses where each chunk must produce compressed output immediately. The compressor remains usable after this call.
Returns
bytes
Compressed bytes for any internally buffered data.
GzipCompressor
5
▼
Gzip compressor using stdlib zlib.
Creates a fresh zlib compressor per instance. Each request gets…
GzipCompressor
5
▼
Gzip compressor using stdlib zlib.
Creates a fresh zlib compressor per instance. Each request gets its own GzipCompressor — no shared state.
Methods
encoding
0
str
▼
property
encoding
0
str
▼
def encoding(self) -> str
Returns
str
compress
1
bytes
▼
compress
1
bytes
▼
def compress(self, data: bytes) -> bytes
Parameters
| Name | Type | Description |
|---|---|---|
data |
— |
Returns
bytes
flush
0
bytes
▼
flush
0
bytes
▼
def flush(self) -> bytes
Returns
bytes
sync_flush
0
bytes
▼
sync_flush
0
bytes
▼
def sync_flush(self) -> bytes
Returns
bytes
Internal Methods 1 ▼
__init__
1
▼
__init__
1
▼
def __init__(self, *, level: int = 6) -> None
Parameters
| Name | Type | Description |
|---|---|---|
level |
— |
Default:6
|
ZstdCompressor
5
▼
Zstd compressor using Python 3.14 stdlib compression.zstd.
Requires Python 3.14+ with compression.…
ZstdCompressor
5
▼
Zstd compressor using Python 3.14 stdlib compression.zstd.
Requires Python 3.14+ with compression.zstd available (PEP 784). Each request gets its own ZstdCompressor — no shared state.
Methods
encoding
0
str
▼
property
encoding
0
str
▼
def encoding(self) -> str
Returns
str
compress
1
bytes
▼
compress
1
bytes
▼
def compress(self, data: bytes) -> bytes
Parameters
| Name | Type | Description |
|---|---|---|
data |
— |
Returns
bytes
flush
0
bytes
▼
flush
0
bytes
▼
def flush(self) -> bytes
Returns
bytes
sync_flush
0
bytes
▼
sync_flush
0
bytes
▼
def sync_flush(self) -> bytes
Returns
bytes
Internal Methods 1 ▼
__init__
1
▼
__init__
1
▼
def __init__(self, *, level: int = 3) -> None
Parameters
| Name | Type | Description |
|---|---|---|
level |
— |
Default:3
|
Functions
_build_encoding_priority
0
tuple[str, ...]
▼
Build encoding priority based on available libraries.
_build_encoding_priority
0
tuple[str, ...]
▼
def _build_encoding_priority() -> tuple[str, ...]
Returns
tuple[str, ...]
negotiate_encoding
1
str | None
▼
Parse Accept-Encoding and return the best supported encoding.
Respects q-value…
negotiate_encoding
1
str | None
▼
def negotiate_encoding(accept_encoding: bytes | str) -> str | None
Parse Accept-Encoding and return the best supported encoding.
Respects q-values and our encoding priority (zstd > gzip). Returns None if no supported encoding matches or the client explicitly declines all encodings.
Parameters
| Name | Type | Description |
|---|---|---|
accept_encoding |
bytes | str |
The Accept-Encoding header value. |
Returns
str | None
create_compressor
1
Compressor
▼
Create a compressor instance for the given encoding.
create_compressor
1
Compressor
▼
def create_compressor(encoding: str) -> Compressor
Parameters
| Name | Type | Description |
|---|---|---|
encoding |
str |
Encoding name (e.g., "zstd", "gzip"). |
Returns
Compressor