The next-generation Python library engineered for modern archive management, leveraging cutting-edge Zstandard compression to deliver superior performance, security, and reliability
Project description
๐บ๐ธ English | ๐จ๐ณ ๆฑ่ฏญ | ๐ช๐ธ espaรฑol | ๐ฏ๐ต ๆฅๆฌ่ช | ๐ฆ๐ช ุงูุนุฑุจูุฉ | ๐ท๐บ ััััะบะธะน | ๐ฉ๐ช Deutsch | ๐ซ๐ท franรงais | ๐ฐ๐ท ํ๊ตญ์ด | ๐ง๐ท portuguรชs
tzst is a next-generation Python library engineered for modern archive management, leveraging cutting-edge Zstandard compression to deliver superior performance, security, and reliability. Built exclusively for Python 3.12+, this enterprise-grade solution combines atomic operations, streaming efficiency, and a meticulously crafted API to redefine how developers handle .tzst/.tar.zst archives in production environments. ๐
In-depth technical analysis article published: Deep Dive into tzst: A Modern Python Archiving Library Based on Zstandard.
โจ Features
- ๐๏ธ High Compression: Zstandard compression for excellent compression ratios and speed
- ๐ Tar Compatibility: Creates standard tar archives compressed with Zstandard
- ๐ป Command Line Interface: Intuitive CLI with streaming support and comprehensive options
- ๐ Python API: Clean, Pythonic API for programmatic use
- ๐ Cross-Platform: Works on Windows, macOS, and Linux
- ๐ Multiple Extensions: Supports both
.tzstand.tar.zstextensions - ๐พ Memory Efficient: Streaming mode for handling large archives with minimal memory usage
- โก Atomic Operations: Safe file operations with automatic cleanup on interruption
- ๐ Secure by Default: Uses the 'data' filter for maximum security during extraction
- ๐จ Enhanced Error Handling: Clear error messages with helpful alternatives
๐ฅ Installation
From GitHub Releases
Download standalone executables that don't require Python installation:
Supported Platforms
| Platform | Architecture | File |
|---|---|---|
| ๐ง Linux | x86_64 | tzst-{version}-linux-amd64.zip |
| ๐ง Linux | ARM64 | tzst-{version}-linux-arm64.zip |
| ๐ช Windows | x64 | tzst-{version}-windows-amd64.zip |
| ๐ช Windows | ARM64 | tzst-{version}-windows-arm64.zip |
| ๐ macOS | Intel | tzst-{version}-darwin-amd64.zip |
| ๐ macOS | Apple Silicon | tzst-{version}-darwin-arm64.zip |
๐ ๏ธ Installation Steps
- ๐ฅ Download the appropriate archive for your platform from the latest releases page
- ๐ฆ Extract the archive to get the
tzstexecutable (ortzst.exeon Windows) - ๐ Move the executable to a directory in your PATH:
- ๐ง Linux/macOS:
sudo mv tzst /usr/local/bin/ - ๐ช Windows: Add the directory containing
tzst.exeto your PATH environment variable
- ๐ง Linux/macOS:
- โ
Verify installation:
tzst --help
๐ฏ Benefits of Binary Installation
- โ No Python required - Standalone executable
- โ Faster startup - No Python interpreter overhead
- โ Easy deployment - Single file distribution
- โ Consistent behavior - Bundled dependencies
๐ฆ From PyPI
Using pip:
pip install tzst
Or using uv (recommended):
uv tool install tzst
๐ง From Source
git clone https://github.com/xixu-me/tzst.git
cd tzst
pip install .
๐ Development Installation
This project uses modern Python packaging standards:
git clone https://github.com/xixu-me/tzst.git
cd tzst
pip install -e .[dev]
๐ Quick Start
๐ป Command Line Usage
# ๐ Create an archive
tzst a archive.tzst file1.txt file2.txt directory/
# ๐ค Extract an archive
tzst x archive.tzst
# ๐ List archive contents
tzst l archive.tzst
# ๐งช Test archive integrity
tzst t archive.tzst
๐ Python API Usage
from tzst import create_archive, extract_archive, list_archive
# Create an archive
create_archive("archive.tzst", ["file1.txt", "file2.txt", "directory/"])
# Extract an archive
extract_archive("archive.tzst", "output_directory/")
# List archive contents
contents = list_archive("archive.tzst", verbose=True)
for item in contents:
print(f"{item['name']}: {item['size']} bytes")
๐ป Command Line Interface
๐ Archive Operations
โ Create Archive
# Basic usage
tzst a archive.tzst file1.txt file2.txt
# With compression level (1-22, default: 3)
tzst a archive.tzst files/ -l 15
# Alternative commands
tzst add archive.tzst files/
tzst create archive.tzst files/
๐ค Extract Archive
# Extract with full directory structure
tzst x archive.tzst
# Extract to specific directory
tzst x archive.tzst -o output/
# Extract specific files
tzst x archive.tzst file1.txt dir/file2.txt
# Extract without directory structure (flat)
tzst e archive.tzst -o output/
# Use streaming mode for large archives
tzst x archive.tzst --streaming -o output/
๐ List Contents
# Simple listing
tzst l archive.tzst
# Verbose listing with details
tzst l archive.tzst -v
# Use streaming mode for large archives
tzst l archive.tzst --streaming -v
๐งช Test Integrity
# Test archive integrity
tzst t archive.tzst
# Test with streaming mode
tzst t archive.tzst --streaming
๐ Command Reference
| Command | Aliases | Description | Streaming Support |
|---|---|---|---|
a |
add, create |
Create or add to archive | N/A |
x |
extract |
Extract with full paths | โ --streaming |
e |
extract-flat |
Extract without directory structure | โ --streaming |
l |
list |
List archive contents | โ --streaming |
t |
test |
Test archive integrity | โ --streaming |
โ๏ธ CLI Options
-v, --verbose: Enable verbose output-o, --output DIR: Specify output directory (extract commands)-l, --level LEVEL: Set compression level 1-22 (create command)--streaming: Enable streaming mode for memory-efficient processing--filter FILTER: Security filter for extraction (data/tar/fully_trusted)--no-atomic: Disable atomic file operations (not recommended)
๐ Security Filters
# Extract with maximum security (default)
tzst x archive.tzst --filter data
# Extract with standard tar compatibility
tzst x archive.tzst --filter tar
# Extract with full trust (dangerous - only for trusted archives)
tzst x archive.tzst --filter fully_trusted
๐ Security Filter Options:
data(default): Most secure. Blocks dangerous files, absolute paths, and paths outside extraction directorytar: Standard tar compatibility. Blocks absolute paths and directory traversalfully_trusted: No security restrictions. Only use with completely trusted archives
๐ Python API
๐ฆ TzstArchive Class
from tzst import TzstArchive
# Create a new archive
with TzstArchive("archive.tzst", "w", compression_level=5) as archive:
archive.add("file.txt")
archive.add("directory/", recursive=True)
# Read an existing archive
with TzstArchive("archive.tzst", "r") as archive:
# List contents
contents = archive.list(verbose=True)
# Extract with security filter
archive.extract("file.txt", "output/", filter="data")
# Test integrity
is_valid = archive.test()
# For large archives, use streaming mode
with TzstArchive("large_archive.tzst", "r", streaming=True) as archive:
archive.extract(path="output/")
โ ๏ธ Important Limitations:
- โ Append Mode Not Supported: Create multiple archives or recreate the entire archive instead
๐ฏ Convenience Functions
๐ create_archive()
from tzst import create_archive
# Create with atomic operations (default)
create_archive(
archive_path="backup.tzst",
files=["documents/", "photos/", "config.txt"],
compression_level=10
)
๐ค extract_archive()
from tzst import extract_archive
# Extract with security (default: 'data' filter)
extract_archive("backup.tzst", "restore/")
# Extract specific files
extract_archive("backup.tzst", "restore/", members=["config.txt"])
# Flatten directory structure
extract_archive("backup.tzst", "restore/", flatten=True)
# Use streaming for large archives
extract_archive("large_backup.tzst", "restore/", streaming=True)
๐ list_archive()
from tzst import list_archive
# Simple listing
files = list_archive("backup.tzst")
# Detailed listing
files = list_archive("backup.tzst", verbose=True)
# Streaming for large archives
files = list_archive("large_backup.tzst", streaming=True)
๐งช test_archive()
from tzst import test_archive
# Basic integrity test
if test_archive("backup.tzst"):
print("Archive is valid")
# Test with streaming
if test_archive("large_backup.tzst", streaming=True):
print("Large archive is valid")
๐ง Advanced Features
๐ File Extensions
The library automatically handles file extensions with intelligent normalization:
.tzst- Primary extension for tar+zstandard archives.tar.zst- Alternative standard extension- Auto-detection when opening existing archives
- Automatic extension addition when creating archives
# These all create valid archives
create_archive("backup.tzst", files) # Creates backup.tzst
create_archive("backup.tar.zst", files) # Creates backup.tar.zst
create_archive("backup", files) # Creates backup.tzst
create_archive("backup.txt", files) # Creates backup.tzst (normalized)
๐๏ธ Compression Levels
Zstandard compression levels range from 1 (fastest) to 22 (best compression):
- Level 1-3: Fast compression, larger files
- Level 3 (default): Good balance of speed and compression
- Level 10-15: Better compression, slower
- Level 20-22: Maximum compression, much slower
๐ Streaming Mode
Use streaming mode for memory-efficient processing of large archives:
โ Benefits:
- Significantly reduced memory usage
- Better performance for archives that don't fit in memory
- Automatic cleanup of resources
๐ฏ When to Use:
- Archives larger than 100MB
- Limited memory environments
- Processing archives with many large files
# Example: Processing a large backup archive
from tzst import extract_archive, list_archive, test_archive
large_archive = "backup_500gb.tzst"
# Memory-efficient operations
is_valid = test_archive(large_archive, streaming=True)
contents = list_archive(large_archive, streaming=True, verbose=True)
extract_archive(large_archive, "restore/", streaming=True)
โก Atomic Operations
All file creation operations use atomic file operations by default:
- Archives created in temporary files first, then atomically moved
- Automatic cleanup if process is interrupted
- No risk of corrupted or incomplete archives
- Cross-platform compatibility
# Atomic operations enabled by default
create_archive("important.tzst", files) # Safe from interruption
# Can be disabled if needed (not recommended)
create_archive("test.tzst", files, use_temp_file=False)
๐จ Error Handling
from tzst import TzstArchive
from tzst.exceptions import (
TzstError,
TzstArchiveError,
TzstCompressionError,
TzstDecompressionError,
TzstFileNotFoundError
)
try:
with TzstArchive("archive.tzst", "r") as archive:
archive.extract()
except TzstDecompressionError:
print("Failed to decompress archive")
except TzstFileNotFoundError:
print("Archive file not found")
except KeyboardInterrupt:
print("Operation interrupted by user")
# Cleanup handled automatically
๐ Performance and Comparison
๐ก Performance Tips
- ๐๏ธ Compression levels: Level 3 is optimal for most use cases
- ๐ Streaming: Use for archives larger than 100MB
- ๐ฆ Batch operations: Add multiple files in single session
- ๐ File types: Already compressed files won't compress much further
๐ vs Other Tools
vs tar + gzip:
- โ Better compression ratios
- โก Faster decompression
- ๐ Modern algorithm
vs tar + xz:
- ๐ Significantly faster compression
- ๐ Similar compression ratios
- โ๏ธ Better speed/compression trade-off
vs zip:
- ๐๏ธ Better compression
- ๐ Preserves Unix permissions and metadata
- ๐ Better streaming support
๐ Requirements
- ๐ Python 3.12 or higher
- ๐ฆ zstandard >= 0.19.0
๐ ๏ธ Development
๐ Setting up Development Environment
This project uses modern Python packaging standards:
git clone https://github.com/xixu-me/tzst.git
cd tzst
pip install -e .[dev]
๐งช Running Tests
# Run tests with coverage
pytest --cov=tzst --cov-report=html
# Or use the simpler command (coverage settings are in pyproject.toml)
pytest
โจ Code Quality
# Check code quality
ruff check src tests
# Format code
ruff format src tests
๐ค Contributing
We welcome contributions! Please read our Contributing Guide for:
- Development setup and project structure
- Code style guidelines and best practices
- Testing requirements and writing tests
- Pull request process and review workflow
๐ Quick Start for Contributors
git clone https://github.com/xixu-me/tzst.git
cd tzst
pip install -e .[dev]
python -m pytest tests/
๐ฏ Types of Contributions Welcome
- ๐ Bug fixes - Fix issues in existing functionality
- โจ Features - Add new capabilities to the library
- ๐ Documentation - Improve or add documentation
- ๐งช Tests - Add or improve test coverage
- โก Performance - Optimize existing code
- ๐ Security - Address security vulnerabilities
๐ Acknowledgments
- Meta Zstandard for the excellent compression algorithm
- python-zstandard for Python bindings
- The Python community for inspiration and feedback
๐ License
Copyright ยฉ Xi Xu. All rights reserved.
Licensed under the BSD 3-Clause license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tzst-1.3.2.tar.gz.
File metadata
- Download URL: tzst-1.3.2.tar.gz
- Upload date:
- Size: 60.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15736f074c628e94db4de48b7cf32841cc44e7e08f80a5cefad20bf11fb9624f
|
|
| MD5 |
bd4d253fd15f6af40d4b033cd4e53025
|
|
| BLAKE2b-256 |
8d3cd148d5dd77932ee9a5aa5449902114a829aa49b69835ed2b0003da31c84a
|
Provenance
The following attestation bundles were made for tzst-1.3.2.tar.gz:
Publisher:
ci.yml on xixu-me/tzst
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tzst-1.3.2.tar.gz -
Subject digest:
15736f074c628e94db4de48b7cf32841cc44e7e08f80a5cefad20bf11fb9624f - Sigstore transparency entry: 1114809100
- Sigstore integration time:
-
Permalink:
xixu-me/tzst@e0cf05dea008cab51a3fd6aa20a1626705251f12 -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/xixu-me
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@e0cf05dea008cab51a3fd6aa20a1626705251f12 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tzst-1.3.2-py3-none-any.whl.
File metadata
- Download URL: tzst-1.3.2-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6805f535904404d04a2e0e78cb58b5d120032fcb83f93ce8afdbcd9ba1020db
|
|
| MD5 |
83a06f1cc1d972658fc80681d81758b4
|
|
| BLAKE2b-256 |
364bb65709643cff1ff1f5234635024d53a8191378e343988c80f82a4704d481
|
Provenance
The following attestation bundles were made for tzst-1.3.2-py3-none-any.whl:
Publisher:
ci.yml on xixu-me/tzst
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tzst-1.3.2-py3-none-any.whl -
Subject digest:
f6805f535904404d04a2e0e78cb58b5d120032fcb83f93ce8afdbcd9ba1020db - Sigstore transparency entry: 1114809103
- Sigstore integration time:
-
Permalink:
xixu-me/tzst@e0cf05dea008cab51a3fd6aa20a1626705251f12 -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/xixu-me
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@e0cf05dea008cab51a3fd6aa20a1626705251f12 -
Trigger Event:
push
-
Statement type: