Apple-Compress
apple-compress provides Python bindings for Apple's native libcompression framework. This library allows Python applications to utilize the highly optimized compression and decompression algorithms available on Apple operating systems (macOS, iOS, etc.). As of April 2026, the current version is 0.2.3. The release cadence is infrequent, typically aligned with bug fixes or minor enhancements rather than a strict schedule.
Common errors
-
ModuleNotFoundError: No module named 'apple_compress'
cause The `apple-compress` package is not installed in the current Python environment.fixRun `pip install apple-compress` to install the library. -
AttributeError: module 'apple_compress' has no attribute 'compress' (or 'LZFSE')
cause Incorrect import or calling non-existent function/attribute, possibly due to misunderstanding the API or a non-standard installation.fixVerify the correct import paths and function names by checking the library's source code on GitHub or by experimenting in a Python shell. The most common functions are `compress` and `decompress` and algorithms `LZFSE`, `ZLIB`. -
RuntimeError: Compression failed: -1 (or similar native library error code)
cause This error typically indicates an issue with the underlying Apple `libcompression` framework, such as an invalid algorithm, corrupted data, or a platform-specific issue, often occurring when run on a non-Apple OS.fixEnsure the code is running on an Apple operating system. Double-check the `algorithm` parameter passed to `compress` or `decompress` functions. Inspect the input data for corruption. If the issue persists, consult Apple's `libcompression` documentation for error code meanings.
Warnings
- breaking This library is designed for and only functions on Apple operating systems (macOS, iOS, watchOS, tvOS). Attempting to use it on Linux, Windows, or other non-Apple platforms will result in runtime errors due to missing native 'libcompression' functionality.
- gotcha The official GitHub README links to a 'Library API Usage' wiki page which does not exist or is not publicly accessible. Users need to infer API usage from source code or examples.
- gotcha The available compression algorithms are dictated by Apple's `libcompression` and may vary slightly or have different performance characteristics across various Apple OS versions. Always test on your target OS version.
Install
-
pip install apple-compress
Imports
- compress
from apple_compress import compress
- decompress
from apple_compress import decompress
- LZFSE
from apple_compress import LZFSE
- ZLIB
from apple_compress import ZLIB
Quickstart
import apple_compress
original_data = b"This is some data to be compressed by apple-compress using LZFSE!"
print(f"Original data length: {len(original_data)} bytes")
# Compress data using the LZFSE algorithm
compressed_data = apple_compress.compress(original_data, algorithm=apple_compress.LZFSE)
print(f"Compressed data length: {len(compressed_data)} bytes")
print(f"Compressed data (first 50 bytes): {compressed_data[:50]}...")
# Decompress data using the same algorithm
decompressed_data = apple_compress.decompress(compressed_data, algorithm=apple_compress.LZFSE)
print(f"Decompressed data length: {len(decompressed_data)} bytes")
assert original_data == decompressed_data
print("Decompression successful! Original and decompressed data match.")