Skip to content

Make brotli compression quality configurable #942

Description

@vdusek

PR #927 added optional brotli request-body compression. The brotli quality is currently hardcoded to 6 in src/apify_client/http_clients/_base.py:

_brotli_compress = functools.partial(brotli.compress, quality=6)

Quality 6 is a reasonable default (better ratio than gzip, much lower CPU than brotli's max quality 11), and it's documented as such in docs/02_concepts/13_compression.mdx. But it's not tunable: users who want maximum compression (quality 11) for bandwidth-bound workloads, or a lower quality to save CPU, currently have no way to change it.

Proposal

Expose the compression quality as a client-level configuration option instead of relying only on the hardcoded value. Points to decide during design:

  • A client parameter (e.g. on ApifyClient / the HTTP client) to override the brotli quality, defaulting to the current 6.
  • Whether to also make the gzip compression level configurable for symmetry.
  • Whether to let users force a specific algorithm rather than relying purely on import-based auto-detection (br when brotli is importable, gzip otherwise) — the current behavior flips to brotli whenever the brotli package is present in the environment, even if it was pulled in transitively.

Context

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions