Core: Fall back to zstandard when stdlib compression.zstd is missing (#4498)

* Core: Fall back to zstandard when stdlib compression.zstd is missing

PEP 784 makes compression.zstd optional, so on Python 3.14+ builds
without libzstd the Avro codec import failed at module load and broke
reading any manifest, and Puffin imports failed the same way when the
zstandard package was missing. Move the backend selection into a shared
pyiceberg.utils.zstd module that tries the stdlib module first, then the
zstandard package, and only raises ImportError on use when neither is
available.

Refs #4495

* Tests: Import ZStandardCodec from its defining module in puffin tests

mypy with no_implicit_reexport rejects importing ZStandardCodec through
the pyiceberg.avro.codecs package, which does not explicitly re-export
it. Import it from pyiceberg.avro.codecs.zstandard_codec instead.

* Tests: Accept stdlib zstd wording for truncated frames in puffin tests

On Python 3.14 the stdlib compression.zstd backend reports a truncated
frame as 'Compressed data ended before the end-of-stream marker was
reached', which the existing match terms do not cover, so the truncated
frame and concatenated frames tests failed on 3.14 only. Widen both
matches with end-of-stream.

* Core: Bump zstandard floor to 0.19.0 and align the fallback with stdlib

The fallback relies on ZstdDecompressionObj.eof and unused_data, so zstandard 0.19.0 is the oldest safe release on Python < 3.14. Empty input now raises the same ZstdError as the stdlib, the module exposes the active backend's ZstdError, and Puffin calls the shared module directly.

* Tests: Move zstd codec tests to the avro file tests and cover the fallback

The codec tests belong with the other codec tests in tests/avro/test_file.py, with exact ZstdError assertions. A new subprocess test blocks only compression.zstd while zstandard is installed and roundtrips through the fallback.

* Core: Make the zstd helper private and test backend selection in-process

Rename pyiceberg/utils/zstd.py to pyiceberg/utils/_zstd.py so compress, decompress and ZstdError do not become public API. Replace the subprocess backend tests with patch.dict and importlib.reload tests, and revert the unrelated beautifulsoup4 churn in uv.lock so only the zstandard specifier changes.

---------

Co-authored-by: TEJA P C <pcteja@users.noreply.github.com>
7 files changed
tree: 8749a6cb1dbb9d15bd0c7b7a100e5837a785bf2a
  1. .github/
  2. dev/
  3. mkdocs/
  4. notebooks/
  5. pyiceberg/
  6. tests/
  7. vendor/
  8. .asf.yaml
  9. .gitignore
  10. .markdown-link-check.json
  11. .markdownlint.yaml
  12. .pre-commit-config.yaml
  13. AGENTS.md
  14. LICENSE
  15. Makefile
  16. MANIFEST.in
  17. NOTICE
  18. pyproject.toml
  19. README.md
  20. SECURITY-THREAT-MODEL.md
  21. setup.py
  22. uv.lock
README.md

Iceberg Python

PyIceberg is a Python library for programmatic access to Iceberg table metadata as well as to table data in Iceberg format. It is a Python implementation of the Iceberg table spec.

The documentation is available at https://py.iceberg.apache.org/.

Get in Touch