Python 3.14 Adds compression.zstd for Zstandard Support
With Python 3.14, the standard library gains a first-party wrapper for Zstandard (zstd), a modern compression algorithm renowned for its high compression ratios and rapid decompression speeds. To avoid clashing with existing PyPI packages named zstd
or zstandard
, PEP 784 consolidates all compression modules under a single compression
namespace, while preserving the legacy imports you already use.
Why Zstandard?¶
Zstandard has emerged as the industry standard for performance-sensitive compression. Benchmarks consistently show:
- Higher ratio than zlib (DEFLATE) and bzip2
- Faster decompression than lzma
- Hardware and filesystem support, including ZFS and Btrfs
Projects from Conda to network protocols now rely on zstd. By bundling it into the standard library, Python enables faster installs, smaller archives, and consistent APIs without external dependencies.
A Unified compression
Package¶
Rather than shadow existing modules, PEP 784 introduces:
This structure prevents naming collisions with third-party packages (zstd
, zstandard
) and lays the groundwork for future additions (e.g., LZ4) without import conflicts.
One-Shot Compression¶
The one-shot API matches existing patterns:
Streaming & File Interfaces¶
Incremental compression and file wrappers mirror the stdlib design:
Output:
Output:
Build-Time Detection & Legacy Support¶
- Unix builds probe for
libzstd
; absence omits the module. - Windows installers vendor
libzstd
for out-of-the-box support. - Top-level imports (
gzip
,bz2
,lzma
,zlib
) continue unchanged. - Dual-version compatibility is achieved via a simple fallback:
Security & Quality Assurance¶
All new C extensions undergo AddressSanitizer and libFuzzer testing. The upstream zstd library is itself well-fuzzed and covered by a bug-bounty program, minimizing memory-safety risks.
Final Thoughts¶
By integrating Zstandard under a clear, conflict-free namespace and extending archive, streaming, and dictionary APIs, Python 3.14 empowers developers with a high-performance compression toolkit, while ensuring existing code and imports remain fully supported.
FAQs
What is Zstandard and why is it added to Python 3.14?
Zstandard (zstd) is a modern compression algorithm offering high compression ratios and fast decompression speeds. Python 3.14 adds it to the standard library to support performance-sensitive use cases and eliminate the need for external dependencies when using zstd.
How is Zstandard integrated into Python’s standard library?
Zstandard is added under the new compression
namespace as compression.zstd
, per PEP 784. This avoids naming conflicts with third-party PyPI packages like zstd
or zstandard
, and paves the way for other algorithms (like LZ4) under the same namespace.
Can I still use the existing compression modules like gzip or lzma?
Yes. Existing top-level imports such as gzip
, bz2
, lzma
, and zlib
remain unchanged and fully supported. The compression
namespace is an addition, not a replacement.
What APIs does compression.zstd provide?
- One-shot APIs for simple
compress()
anddecompress()
operations - Streaming interfaces (
compressobj
,decompressobj
) for chunked data - File wrappers for working with
.zst
files using familiar I/O patterns
How is compatibility and security handled in this new module?
- Python on Windows ships with vendored
libzstd
- Unix builds detect
libzstd
at build time - The C extension is tested with AddressSanitizer, libFuzzer, and benefits from upstream bug bounty coverage for
zstd
- Dual-version compatibility can be maintained with fallback imports if needed