Skip to content

Conversation

@xkrogen
Copy link
Member

@xkrogen xkrogen commented Dec 16, 2025

Description

This PR implements graceful degradation for the optional compression dependencies lz4 and zstandard. Previously, the client would fail to import if these libraries were missing, even if they weren't being used.

Key changes:

  • Wrapped imports of lz4.block and zstandard in try-except ImportError blocks and track the failures in CODECS_UNAVAILABLE
  • Updated trino.dbapi / trino.client to dynamically filter the default encoding list based on which codecs could be loaded, including automatically informing the server if some encodings aren't supported (via X-Trino-Query-Data-Encoding header)
  • Updated to raise ValueError with the original ImportError message if a user explicitly requests an encoding that is not available.

Closes #584

Non-technical explanation

The Trino Python client no longer crashes on startup if the optional lz4 or zstandard libraries are not installed. Instead, it automatically disables the compression methods that rely on them. If you explicitly try to use a compression method that isn't installed, the client will raise an error explaining that the required library is missing.

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text:

* Make `lz4` and `zstandard` optional dependencies. The client now gracefully handles missing/broken compression libraries by disabling the corresponding encoding. ({issue}`585`)

@cla-bot cla-bot bot added the cla-signed label Dec 16, 2025
@xkrogen
Copy link
Member Author

xkrogen commented Dec 16, 2025

cc @wendigo @hashhar @mdesmet

@hashhar hashhar requested a review from damian3031 December 16, 2025 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Trino Python client is broken if lz4/zstd native libs can't be loaded instead of degrading gracefully

1 participant