Registry / serialization / compressed-rtf

compressed-rtf

JSON →
library1.0.7pypypi✓ verified 25d ago

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.

pip install compressed-rtf
INSTALL
IMPORT
SIG · COMPRESSED-RTF
C
compressed-rtf
serializationpythonv1.0.7
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compress
from compressed_rtf import compress
Used to compress RTF byte data.
decompress
from compressed_rtf import decompress
Used to decompress RTF byte data.

Demonstrates how to compress and decompress RTF byte data using the `compress` and `decompress` functions.

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]}...")
Debug
Known issues
gotchaThis 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`.
fix
Ensure that the RTF data you are processing conforms to the LZFu compression scheme used by Microsoft products. For general compression, consider Python's built-in `zlib` or `gzip` modules.
affects: <1.0.7
gotchaVersion 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.
fix
Upgrade to version 1.0.7 or later to benefit from packaging stability fixes: `pip install --upgrade compressed-rtf`.
affects: <1.0.7
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'compressed_rtf'
The `compressed-rtf` package is not installed in your current Python environment, or there is a typo in the import statement.
fix
Ensure the package is installed using pip: `pip install compressed-rtf`
error: metadata-generation-failed × Encountered error while generating package metadata.
This error often occurs during installation on Windows, indicating a problem with building the package's metadata, potentially due to missing C++ build tools or an upstream compatibility issue with the `compressed-rtf` package itself on Windows.
fix
Try updating `pip` and `setuptools` (`pip install --upgrade pip setuptools`). If the issue persists, ensure you have C++ build tools for Python installed (e.g., from Visual Studio Build Tools). A direct fix for the reported upstream issue may require using a pre-compiled wheel or a different environment.
ValueError: Invalid compressed RTF data
The input provided to the `decompress` function is not a valid compressed Rich Text Format (RTF) byte string, meaning it lacks the correct headers (like 'LZFu' or 'MELA') or structure, or the data itself is corrupted.
fix
Ensure the data passed to `decompress()` is a byte string obtained from a legitimate compressed RTF source. Verify the integrity of your input data. You might need to inspect the first few bytes of your input to confirm it matches the expected RTF compression signatures (e.g., '#\x00\x00\x00"\x00\x00\x00LZFu' for compressed data or '.\x00\x00\x00"\x00\x00\x00MELA' for raw/uncompressed data as expected by the library).
Upgrade
Version history
1.0.7latest on PyPI · released Mar 24, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
compressed-rtf — pip install compressed-rtf · libregistry