Registry / data / lilcom

lilcom

JSON →
library1.8.2pypypi✓ verified 22d ago

Lilcom is a Python library that provides lossy compression for sequence data stored in NumPy arrays. It efficiently compresses floating-point or 16-bit integer NumPy arrays into byte strings, typically used in machine learning applications for storing training data and models. The current version is 1.8.2, and it has a fairly active release cadence, with updates addressing compatibility and functionality.

pip install lilcom
INSTALL
IMPORT
SIG · LILCOM
L
lilcom
datapythonv1.8.2
Install
3.7s avg
Import
264ms
Disk
88MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.2 · 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
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.7s · import 0.264s · 86MB
88MB installed
● package 88MB
Code
Verified usage

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

lilcom
import lilcom
compress
lilcom.compress(...)
decompress
lilcom.decompress(...)

This quickstart demonstrates how to compress a NumPy array using `lilcom.compress()` and then decompress it using `lilcom.decompress()`. Note that `lilcom` is a lossy compression utility, so the decompressed array will not be exactly identical to the original. The `tick_power` argument controls the precision of the compression.

import numpy as np import lilcom # Create a sample NumPy array a = np.random.randn(300, 500).astype(np.float32) # Compress the array (default tick_power=-8, controls accuracy) a_compressed = lilcom.compress(a) # Decompress the array, specifying original dtype a_decompressed = lilcom.decompress(a_compressed, dtype=a.dtype) print(f"Original array shape: {a.shape}, dtype: {a.dtype}") print(f"Compressed data size: {len(a_compressed)} bytes") print(f"Decompressed array shape: {a_decompressed.shape}, dtype: {a_decompressed.dtype}") print(f"Max absolute error: {np.max(np.abs(a - a_decompressed)):.2e}")
Debug
Known issues
gotchaLilcom provides *lossy* compression. The decompressed data will not be bit-for-bit identical to the original array. The amount of error is controlled by the `tick_power` argument (default -8), which determines the step size for discretized values.
fix
Be aware of the lossy nature and choose an appropriate `tick_power` for your application's accuracy requirements. `2**(tick_power-1)` gives the maximum error per element.
affects: All versions
breakingThe method for controlling compression accuracy changed. Older versions of Lilcom might have used `bits_per_sample`. Current versions (e.g., 1.8.2 and recent GitHub README) use `tick_power` to specify the quantization step size.
fix
If migrating from older code, replace `bits_per_sample` with `tick_power`. The `tick_power` argument (default: -8) is the power of 2 used for the step size between discretized values.
affects: Prior to ~v1.7 (exact transition not specified, but observed in documentation updates)
breakingLilcom requires Python 3.6 or newer. It is not compatible with Python 2.x. Attempts to install or run on unsupported Python versions will fail.
fix
Ensure your environment uses Python 3.6 or higher. Upgrade Python if necessary.
affects: All versions
gotchaThe underlying algorithm is highly vulnerable to transmission errors. Even a single bit error in the compressed byte string can make the entire file or sequence unreadable during decompression. This is acceptable for its target machine learning applications where data integrity is often handled at a higher level or re-generated.
fix
Implement robust error handling, retransmission, or checksums if storing or transmitting compressed data in environments prone to bit errors and where data recovery is critical.
affects: All versions
gotchaIf installing `lilcom` from source (e.g., if pre-compiled wheels are not available for your specific platform/Python version), a C++ compiler (like g++ or clang) is required on your system.
fix
Ensure a C++ compiler is installed and accessible in your system's PATH before attempting a source installation (e.g., `apt-get install build-essential` on Debian/Ubuntu or Xcode Command Line Tools on macOS).
affects: All versions (for source installs)
Errors
Common errors & fixes
Lilcom requires Python 3.6 or newer
The `lilcom` library is not compatible with Python 2.x and requires Python 3.6 or a more recent version to function.
fix
Ensure your Python environment is version 3.6 or higher. Upgrade Python if necessary, for example, by using `python3` instead of `python` or updating your virtual environment.
AttributeError: type object 'Distribution' has no attribute '_finalize_feature_opts'
This error typically occurs during installation, especially with older Python 3.7 versions, due to an incompatibility between `setuptools` and `lilcom`'s build process.
fix
Try downgrading your `setuptools` package before installing `lilcom`: `pip install 'setuptools<60'` or ensure you are using a more recent Python 3.x version (e.g., 3.8+).
ValueError: lilcom: Length of string was too short
This error indicates that the byte string provided to `lilcom.decompress()` is either corrupted, incomplete, or not a valid `lilcom` compressed string.
fix
Verify the integrity of the compressed byte string. Ensure the entire compressed data was successfully stored and retrieved. If the data was transmitted, check for transmission errors. Also, confirm that the data being decompressed was indeed compressed using `lilcom.compress()`.
TypeError: compress() got an unexpected keyword argument 'bits_per_sample'
In newer versions of `lilcom` (e.g., 1.8.2), the argument for controlling compression accuracy was changed from `bits_per_sample` to `tick_power`.
fix
Replace `bits_per_sample` with `tick_power` in your call to `lilcom.compress()`. For example, change `lilcom.compress(data, bits_per_sample=N)` to `lilcom.compress(data, tick_power=M)`.
Upgrade
Version history
1.8.2latest on PyPI · released Jan 15, 2026
Audit
Dependencies
numpyrequiredCore functionality relies on NumPy arrays for data handling.
cmakeoptionalRequired for building from source if pre-compiled wheels are not available for your system/Python version. Version 1.6 and later typically provide pre-compiled libraries.
Agent activity
6 hits · last 30 days
node
4
Amazon
1
Resources
lilcom — pip install lilcom · libregistry