PPMd Compression Library

1.3.1 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates the basic usage of pyppmd to compress and decompress a byte string. It initializes an `Encoder` and `Decoder`, processes data, and then verifies the integrity of the decompressed output.

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!")

view raw JSON →