tzst
raw JSON → 1.3.3 verified Fri May 01 auth: no python
A Python library for creating and extracting TAR archives with Zstandard (zstd) compression. It provides a high-level API similar to Python's built-in tarfile but with superior compression ratios and performance. Current version 1.3.3, requires Python >=3.12.
pip install tzst Common errors
error ImportError: cannot import name 'open' from 'tzst' ↓
cause Older version of tzst may not have open; or tzst not installed.
fix
Upgrade to latest: pip install --upgrade tzst
error TypeError: open() got an unexpected keyword argument 'level' ↓
cause The open() function uses 'compression_level' not 'level'.
fix
Use compression_level parameter: open('archive.tar.zst', 'w', compression_level=5)
Warnings
breaking tzst requires Python >=3.12. Older Python versions will raise ImportError. ↓
fix Upgrade Python to 3.12 or later.
gotcha The open() function has a different signature from zstandard or tarfile. Do not use zstandard's open() as it produces raw zstd streams, not tzst archives. ↓
fix Always use from tzst import open.
Imports
- open
from tzst import open - TarInfo wrong
from tarfile import TarInfocorrectfrom tzst import TarInfo
Quickstart
from tzst import open
import os
# Create a tzst archive
with open('example.tar.zst', 'w') as tf:
tf.add('file1.txt')
tf.add('directory/')
# Extract a tzst archive
with open('example.tar.zst', 'r') as tf:
tf.extractall(path='./extracted')
# Compress existing tar file
import tarfile
with tarfile.open('example.tar', 'w') as tar:
tar.add('file1.txt')
# then compress with zstd? Actually tzst handles it directly
# For reading stream
with open('example.tar.zst', 'r') as tf:
for member in tf:
print(member.name)