Compressed RTF
Compressed Rich Text Format (RTF) compression and decompression package. It supports the LZFu compression format, based on the Microsoft RTF Compression Algorithm. The current version is 1.0.7, and releases are infrequent, primarily for bug fixes.
Warnings
- gotcha This library implements the specific Microsoft Rich Text Format (RTF) Compression Algorithm (LZFu) outlined in MS-OXRTFCP. It is not a general-purpose compression library and should not be confused with standard Python compression modules like `zlib` or `gzip`.
- gotcha Version 1.0.7 resolved a circular import issue in `setup.py` (Pull Request #19) that could affect packaging and installation in certain environments. While not a direct API breaking change, users on older versions (<=1.0.6) might encounter installation or build issues.
Install
-
pip install compressed-rtf
Imports
- compress
from compressed_rtf import compress
- decompress
from compressed_rtf import decompress
Quickstart
from compressed_rtf import compress, decompress
# Example RTF data (must be bytes)
rtf_data = b'{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}{\f1\fnil\fcharset2 Symbol;}}
{\pard\sa200\sl276\slmult1\f0\fs22\lang9 This is some \b compressed\b0 RTF data.\par}
}
'
# Compress the data
compressed_bytes = compress(rtf_data)
print(f"Original size: {len(rtf_data)} bytes")
print(f"Compressed size: {len(compressed_bytes)} bytes")
# Decompress the data
decompressed_bytes = decompress(compressed_bytes)
# Verify decompression
assert decompressed_bytes == rtf_data
print("Decompression successful!")
print(f"Decompressed content: {decompressed_bytes.decode('ascii', errors='ignore')[:50]}...")