Python 3.14+compression.zstdfunction
compression.zstd.open()
zstd files
Opens a .zst file for reading or writing in binary or text mode, the Zstandard counterpart of gzip.open.
Syntax
compression.zstd.open(file, /, mode='rb', *, level=None, options=None, zstd_dict=None, encoding=None, errors=None, newline=None)
The default mode is 'rb', binary, so read() returns bytes; for str use 'rt' and an explicit encoding='utf-8', otherwise the locale encoding is used. Text modes exist only in open(): ZstdFile itself rejects 'rt' with ValueError. The compression level is accepted only when writing; passing level for reading is an error. Mode 'a' appends a new frame, and reading returns the whole file.
Examples
# Python 3.14+
from compression import zstd # → ? нужна сборка CPython с libzstd
with zstd.open('notes.zst', 'wt', encoding='utf-8') as f:
f.write('привет\n')
with zstd.open('notes.zst', 'rt', encoding='utf-8') as f:
print(repr(f.read())) # → 'привет\n'
with zstd.open('notes.zst') as f:
print(type(f).__name__, type(f.read()).__name__) # → ZstdFile bytes
See also
Open in the full glossarydocs.python.orgReport an inaccuracy