Backports Zstandard (zstd)
raw JSON → 1.3.0 verified Tue May 12 auth: no python install: verified
backports-zstd is a library that backports the `compression.zstd` module, introduced in Python 3.14, to older Python versions (3.9 to 3.13). It provides a Pythonic interface for Zstandard compression, aiming to be as close as possible to the standard library's implementation. The library is currently at version 1.3.0 and is actively maintained, though it is designed to be superseded by the standard library module in Python 3.14 and later.
pip install "backports.zstd; python_version < '3.14'" Common errors
error ModuleNotFoundError: No module named 'compression' ↓
cause The `backports-zstd` library, which provides the `compression.zstd` module for older Python versions, is either not installed, or you are on Python 3.14+ and trying to use the backport instead of the built-in standard library module.
fix
If your Python version is between 3.9 and 3.13, ensure
backports-zstd is installed: pip install backports-zstd. If you are using Python 3.14 or newer, you do not need backports-zstd as compression.zstd is part of the standard library; simply use from compression import zstd. error ERROR: Package 'backports-zstd' requires a different Python. Your Python 3.14.x does not match '~=3.9, <3.14'. ↓
cause The `backports-zstd` library is intentionally designed not to install on Python 3.14 or newer because the `compression.zstd` module it backports is natively available in the standard library from Python 3.14 onwards.
fix
Do not install
backports-zstd on Python 3.14 or later. Instead, directly use the built-in compression.zstd module by importing it: from compression import zstd. error AttributeError: 'zstd.ZstdDecompressionReader' object has no attribute 'fileno' ↓
cause This error occurs when attempting to use a `zstd.ZstdDecompressionReader` object (returned by `zstd.open`) in a context that expects a low-level file descriptor (like certain `subprocess` arguments expecting `fileno`), which the Python-level file-like object does not always provide.
fix
Instead of passing the
zstd.open object directly to functions requiring fileno, process the data by reading it in chunks, decompressing it fully into memory (e.g., zstd.decompress), or pipe the data through subprocess.PIPE and manage the input/output streams programmatically. Warnings
breaking This library is intentionally not installable on Python 3.14 or later. For Python 3.14+, the `compression.zstd` module is part of the standard library and should be used directly. ↓
fix Remove `backports.zstd` from dependencies for Python 3.14+ environments and use `from compression import zstd` directly. Conditional imports are recommended for multi-version compatibility.
deprecated The `backports.zstd` library is scheduled for deprecation with the end of official support for Python 3.13 (October 2029). ↓
fix Plan to migrate to `compression.zstd` in the Python standard library as projects transition to Python 3.14 or newer. Conditional imports will facilitate this transition.
gotcha For code compatible with both Python versions below 3.14 and 3.14+, a conditional import statement is required to correctly import the `zstd` module. ↓
fix Implement conditional imports like `if sys.version_info >= (3, 14): from compression import zstd else: from backports import zstd`.
gotcha By default, `backports.zstd` uses a statically bundled `libzstd`. If you prefer to use a system-installed `libzstd`, you must pass a specific argument during the build phase. ↓
fix When installing, use `pip install --config-settings=--build-option=--system-zstd backports.zstd`. During testing with system `libzstd`, set `BACKPORTSZSTD_SKIP_EXTENSION_TEST=1`.
Install
pip install backports.zstd Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) "backports.zstd; wheel - 0.00s 19.4M
3.10 alpine (musl) "backports.zstd; - - 0.00s 19.4M
3.10 alpine (musl) backports.zstd wheel - 0.00s 19.4M
3.10 alpine (musl) backports.zstd - - 0.00s 19.4M
3.10 slim (glibc) "backports.zstd; wheel 1.7s 0.00s 20M
3.10 slim (glibc) "backports.zstd; - - 0.00s 20M
3.10 slim (glibc) backports.zstd wheel 1.6s 0.00s 20M
3.10 slim (glibc) backports.zstd - - 0.00s 20M
3.11 alpine (musl) "backports.zstd; wheel - 0.00s 21.4M
3.11 alpine (musl) "backports.zstd; - - 0.00s 21.4M
3.11 alpine (musl) backports.zstd wheel - 0.00s 21.4M
3.11 alpine (musl) backports.zstd - - 0.00s 21.4M
3.11 slim (glibc) "backports.zstd; wheel 1.7s 0.00s 22M
3.11 slim (glibc) "backports.zstd; - - 0.00s 22M
3.11 slim (glibc) backports.zstd wheel 1.8s 0.00s 22M
3.11 slim (glibc) backports.zstd - - 0.00s 22M
3.12 alpine (musl) "backports.zstd; wheel - 0.00s 13.3M
3.12 alpine (musl) "backports.zstd; - - 0.00s 13.2M
3.12 alpine (musl) backports.zstd wheel - 0.00s 13.3M
3.12 alpine (musl) backports.zstd - - 0.00s 13.2M
3.12 slim (glibc) "backports.zstd; wheel 1.5s 0.00s 14M
3.12 slim (glibc) "backports.zstd; - - 0.00s 14M
3.12 slim (glibc) backports.zstd wheel 1.5s 0.00s 14M
3.12 slim (glibc) backports.zstd - - 0.00s 14M
3.13 alpine (musl) "backports.zstd; wheel - 0.00s 13.0M
3.13 alpine (musl) "backports.zstd; - - 0.00s 12.9M
3.13 alpine (musl) backports.zstd wheel - 0.00s 13.0M
3.13 alpine (musl) backports.zstd - - 0.00s 12.9M
3.13 slim (glibc) "backports.zstd; wheel 1.6s 0.00s 13M
3.13 slim (glibc) "backports.zstd; - - 0.00s 13M
3.13 slim (glibc) backports.zstd wheel 1.6s 0.00s 13M
3.13 slim (glibc) backports.zstd - - 0.00s 13M
3.9 alpine (musl) "backports.zstd; wheel - 0.00s 18.9M
3.9 alpine (musl) "backports.zstd; - - 0.00s 18.9M
3.9 alpine (musl) backports.zstd wheel - 0.00s 18.9M
3.9 alpine (musl) backports.zstd - - 0.00s 18.9M
3.9 slim (glibc) "backports.zstd; wheel 1.9s 0.00s 19M
3.9 slim (glibc) "backports.zstd; - - 0.00s 19M
3.9 slim (glibc) backports.zstd wheel 1.9s 0.00s 19M
3.9 slim (glibc) backports.zstd - - 0.00s 19M
Imports
- zstd
import sys if sys.version_info >= (3, 14): from compression import zstd else: from backports import zstd - tarfile
import sys if sys.version_info >= (3, 14): import tarfile else: from backports.zstd import tarfile - zipfile
import sys if sys.version_info >= (3, 14): import zipfile else: from backports.zstd import zipfile - register_shutil
import sys if sys.version_info < (3, 14): from backports.zstd import register_shutil register_shutil()
Quickstart last tested: 2026-04-24
import sys
if sys.version_info >= (3, 14):
from compression import zstd
else:
from backports import zstd
original_data = b"Hello, Zstandard backport! " * 100
# Compress data
compressed_data = zstd.compress(original_data)
print(f"Original size: {len(original_data)} bytes")
print(f"Compressed size: {len(compressed_data)} bytes")
# Decompress data
decompressed_data = zstd.decompress(compressed_data)
print(f"Decompressed size: {len(decompressed_data)} bytes")
assert original_data == decompressed_data