Skip to content

Commit 41c6f39

Browse files
dheerajitbhuvdusek
andauthored
docs: document gzip default and brotli extra for request compression (#1209)
Closes: #1179 The `compression` docstring on `ApifyClient` / `ApifyClientAsync` did not say what the default is or that `'brotli'` needs an optional extra. That made the difference from the JS client (which defaults to brotli via `node:zlib`) hard to discover. --- Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
1 parent f5e005f commit 41c6f39

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/apify_client/_apify_client.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ def __init__(
154154
user_agent_suffix: Extra part or parts appended to the default `User-Agent` header, separated by `; `, for
155155
example to identify the tool built on top of the client. With `with_custom_http_client`, pass it to
156156
the HTTP client's constructor.
157-
compression: Compression algorithm for request bodies. Pass a string literal to select an algorithm,
158-
or an `HttpCompressor` instance for finer-grained control.
157+
compression: Compression algorithm for request bodies. Defaults to `'gzip'`. Pass a string literal to select
158+
an algorithm, or an `HttpCompressor` instance for finer-grained control. `'brotli'` needs the `brotli`
159+
extra (`pip install "apify-client[brotli]"`). It is not the default because the `brotli` package is a C
160+
extension, while gzip support is part of the Python standard library.
159161
160162
Raises:
161163
ValueError: If `max_retries` is negative.
164+
ImportError: If `compression` is `'brotli'` and the `brotli` extra is not installed.
162165
"""
163166
if max_retries < 0:
164167
raise ValueError(f'max_retries must be a non-negative integer, got {max_retries}')
@@ -534,11 +537,14 @@ def __init__(
534537
user_agent_suffix: Extra part or parts appended to the default `User-Agent` header, separated by `; `, for
535538
example to identify the tool built on top of the client. With `with_custom_http_client`, pass it to
536539
the HTTP client's constructor.
537-
compression: Compression algorithm for request bodies. Pass a string literal to select an algorithm,
538-
or an `HttpCompressor` instance for finer-grained control.
540+
compression: Compression algorithm for request bodies. Defaults to `'gzip'`. Pass a string literal to select
541+
an algorithm, or an `HttpCompressor` instance for finer-grained control. `'brotli'` needs the `brotli`
542+
extra (`pip install "apify-client[brotli]"`). It is not the default because the `brotli` package is a C
543+
extension, while gzip support is part of the Python standard library.
539544
540545
Raises:
541546
ValueError: If `max_retries` is negative.
547+
ImportError: If `compression` is `'brotli'` and the `brotli` extra is not installed.
542548
"""
543549
if max_retries < 0:
544550
raise ValueError(f'max_retries must be a non-negative integer, got {max_retries}')

0 commit comments

Comments
 (0)