PPMd Compression Library
pyppmd is a Python wrapper for the PPMd (Prediction by Partial Matching) compression algorithm, offering both compression and decompression capabilities. It is implemented as a C-extension for performance. The current version is 1.3.1, and it receives updates periodically, primarily for maintenance, bug fixes, and minor feature enhancements.
Warnings
- gotcha The PPMd8 Decoder, particularly in versions prior to 1.x, has known issues including incorrect output, wrong end-of-file (EOF) status detection, and potential deadlocks with certain parameter combinations. While improvements have been made, caution is advised.
- breaking pyppmd requires Python 3.10 or newer. Attempting to install or use it on older Python versions will result in installation failures or runtime errors.
- gotcha While pyppmd generally handles data streams, the `compress` and `decompress` methods are designed for single-shot operations with complete byte strings. Using them incrementally or with partial data without careful state management may lead to corruption or errors.
Install
-
pip install pyppmd
Imports
- PPMdEncoder
from pyppmd import PPMdEncoder
- PPMdDecoder
from pyppmd import PPMdDecoder
Quickstart
import pyppmd
# Prepare some data
original_data = b"This is a test string to be compressed multiple times. " * 100
# Initialize encoder and decoder
encoder = pyppmd.PPMdEncoder()
decoder = pyppmd.PPMdDecoder()
# Compress the data
compressed_data = encoder.compress(original_data)
print(f"Original size: {len(original_data)} bytes")
print(f"Compressed size: {len(compressed_data)} bytes")
# Decompress the data
decompressed_data = decoder.decompress(compressed_data)
# Verify decompression
assert original_data == decompressed_data
print("Decompression successful and data matches original!")