Backport of compression.zstd
Actively maintained. Last release 4 days ago, commits in 6 of the last 26 weeks. A safe choice.
pip install backports-zstdInstall
Add the following dependency to your project:
backports.zstd ; python_version<'3.14'
…or just run pip install backports.zstd.
Usage
When importing a module needing Zstandard support, use a conditional import based on the version of Python. See below for examples.
zstd
import sys
if sys.version_info >= (3, 14):
from compression import zstd
else:
from backports import zstd
# use the zstd module, for example:
zstd.compress(b"Hello, world!")
Refer to the official Python documentation for usage of the module.
tarfile
import sys
if sys.version_info >= (3, 14):
import tarfile
else:
from backports.zstd import tarfile
# use the tarfile module, for example:
with tarfile.open("archive.tar.zst") as tar:
tar.list()
This tarfile modules is backported from Python 3.14 and includes Zstandard-specific
features such as: explicit modes for opening files (e.g. r:zstd), specific arguments
(e.g. zstd_dict)… refer to the official Python documentation for more
info.
Moreover, the CLI is available as well: python -m backports.zstd.tarfile.
zipfile
import sys
if sys.version_info >= (3, 14):
import zipfile
else:
from backports.zstd import zipfile
# use the zipfile module, for example:
with zipfile.ZipFile("archive.zip", "w") as zf:
zf.writestr("hello.txt", "Hi!", zipfile.ZIP_ZSTANDARD)