{"id":844,"library":"cramjam","title":"cramjam","description":"cramjam provides extremely thin and easy-to-install Python bindings to various de/compression algorithms implemented in Rust. It offers access to popular algorithms like Snappy, Brotli, Bzip2, Lz4, Gzip, Zlib, Deflate, ZSTD, and XZ/LZMA. The library, currently at version 2.11.0, is actively maintained with a regular release cadence.","status":"active","version":"2.11.0","language":"python","source_language":"en","source_url":"https://github.com/milesgranger/cramjam","tags":["compression","decompression","snappy","zstd","bz2","gzip","lz4","brotli","deflate","blosc2","rust","performance"],"install":[{"cmd":"pip install --upgrade cramjam","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Required for running the Python bindings.","package":"python","optional":false}],"imports":[{"note":"General import for accessing all compression variants (e.g., cramjam.snappy, cramjam.brotli).","symbol":"cramjam","correct":"import cramjam"},{"note":"Import a specific compression algorithm directly.","symbol":"snappy","correct":"from cramjam import snappy"},{"note":"Used for efficient in-memory buffer operations, particularly with de/compress_into methods.","symbol":"Buffer","correct":"from cramjam import Buffer"}],"quickstart":{"code":"import cramjam\n\noriginal_data = b\"This is some data to compress using cramjam!\"\n\n# Compress data using Snappy\ncompressed_data = cramjam.snappy.compress(original_data)\nprint(f\"Original size: {len(original_data)} bytes\")\nprint(f\"Compressed size (Snappy): {len(compressed_data)} bytes\")\n\n# Decompress data\ndecompressed_data = cramjam.snappy.decompress(compressed_data)\nprint(f\"Decompressed data matches original: {original_data == decompressed_data}\")\n\n# Example with Brotli\ncompressed_brotli = cramjam.brotli.compress(original_data)\nprint(f\"Compressed size (Brotli): {len(compressed_brotli)} bytes\")\ndecompressed_brotli = cramjam.brotli.decompress(compressed_brotli)\nprint(f\"Decompressed Brotli matches original: {original_data == decompressed_brotli}\")\n\n# Using cramjam.Buffer for in-place operations\nfrom cramjam import snappy, Buffer\nimport numpy as np\n\ndata_np = np.frombuffer(b'some bytes here for buffer', dtype=np.uint8)\noutput_buffer = Buffer()\nsnappy.compress_into(data_np, output_buffer)\n\noutput_buffer.seek(0) # Reset buffer position for reading\ndecompressed_buffer_data = snappy.decompress(output_buffer)\nprint(f\"Buffer decompressed data matches original: {bytes(data_np) == bytes(decompressed_buffer_data)}\")","lang":"python","description":"This quickstart demonstrates basic compression and decompression using Snappy and Brotli. It also includes an example of using `cramjam.Buffer` for more efficient in-place compression operations, which is beneficial when dealing with `bytes`, `bytearray`, or `numpy.array` objects."},"warnings":[{"fix":"Explicitly set the `compression_level` parameter when calling `cramjam.lz4.compress` or ensure any integrating library configures it appropriately. The default behavior may vary and impact performance.","message":"When integrating `cramjam`'s LZ4 implementation or migrating from other LZ4 libraries, be aware that the default compression level in `cramjam`'s LZ4 might differ. For example, a change from level 0 to 9 in a dependent library using `cramjam`'s LZ4 was observed to cause significant performance degradation (over 100% latency increase) if not explicitly set. Always verify the `compression_level` if performance is critical.","severity":"gotcha","affected_versions":"All versions (behavioral difference)"},{"fix":"Pass the `output_len=some_integer` argument to `compress` or `decompress` functions when the final size is predictable.","message":"For significant performance improvements (1.5-3x speedup), especially when decompressing or compressing to a standard `bytes` or `bytearray` object, provide the `output_len` argument if the exact output length is known beforehand. This allows for single buffer allocation. This optimization is less relevant when using `cramjam.Buffer` or `cramjam.File` objects.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the official `cramjam` GitHub repository or documentation for instructions on building from source with experimental features if you need to use them.","message":"Some compression algorithms (e.g., Blosc2, ISA-L backends like igzip, ideflate, izlib) are considered experimental. These typically require building `cramjam` from source with specific feature flags enabled. They are not available out-of-the-box with a standard `pip install`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `numpy` is installed in your environment by running `pip install numpy`.","message":"The test script or some functionalities within `cramjam` rely on `numpy`, which is not installed by default in the test environment. This results in a `ModuleNotFoundError` if `numpy` is not available.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure that `cramjam` is installed from a compatible wheel for your Alpine Python environment, or install necessary build tools (e.g., `rust`, `cargo`, `musl-dev`, `python3-dev`, `build-base`) before installing `cramjam` to allow it to compile correctly from source. Test core compression/decompression functionality after installation.","message":"When running `cramjam` on minimal Linux distributions like Alpine, especially with Python versions that might not have readily available pre-built wheels, core compression/decompression functionalities (e.g., Snappy, Brotli) might fail to correctly decompress data, resulting in `Decompressed data matches original: False`. This typically occurs if `cramjam`'s Rust extensions are not compiled against the correct system libraries, or if necessary build dependencies are missing during installation. Always verify `cramjam`'s functionality on Alpine if you are using it.","severity":"breaking","affected_versions":"All versions (platform-specific behavioral difference on Alpine/musl-based systems)"}],"env_vars":null,"last_verified":"2026-05-12T20:20:15.471Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install cramjam`","cause":"The `cramjam` package is not installed in your current Python environment, or the environment where the code is being run does not have access to it.","error":"ModuleNotFoundError: No module named 'cramjam'"},{"fix":"Ensure you are using a Python version supported by the `cramjam` wheels (typically Python 3.8+). If in Docker, try changing the Python version in your Dockerfile. Sometimes, pre-installing related system libraries (like `libsnappy-dev` for `python-snappy`'s transitive dependency on `cramjam`) can help, although `cramjam` itself aims to be dependency-free.","cause":"Installation issues can arise due to incompatible Python versions, especially in constrained environments like Docker, or if there are conflicts with other dependencies (e.g., `fastparquet` or `python-snappy`) that rely on `cramjam` and have specific environment requirements.","error":"error installing cramjam package"},{"fix":"Downgrade to a stable and widely supported Python version (e.g., Python 3.9, 3.10, 3.11) that has pre-built `cramjam` wheels, or check the `cramjam` GitHub issues for compatibility with the specific Python version you are using.","cause":"This severe error can occur due to fundamental incompatibilities, often when `cramjam` is used with very new or pre-release Python versions, leading to memory access violations within the underlying Rust bindings.","error":"Fatal Python error: Segmentation fault"},{"fix":"Verify that the input data is indeed compressed with the `cramjam` algorithm you are attempting to use (e.g., `cramjam.snappy.decompress` for Snappy-compressed data) and that the data itself is not truncated or corrupted. Ensure the correct bytes-like object is passed.","cause":"This error indicates that the data provided to a `cramjam` decompression function is not in the expected compressed format, is corrupted, or was compressed with a different algorithm than the one being used for decompression.","error":"cramjam.DecompressionError: Invalid input or corrupted data"}],"ecosystem":"pypi","meta_description":null,"install_score":80,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.11.0","cli_name":"","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","installed_version":"2.11.0","pypi_latest":"2.11.0","is_stale":false,"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"22.6M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"22.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0,"mem_mb":0.1,"disk_size":"23M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"23M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"24.4M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"24.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0,"mem_mb":0.1,"disk_size":"24M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"16.3M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"16.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0,"mem_mb":0.1,"disk_size":"16M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"16M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0.3,"disk_size":"16.0M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.3,"disk_size":"15.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0,"mem_mb":0.1,"disk_size":"16M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"16M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"22.1M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"22.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0,"mem_mb":0.1,"disk_size":"22M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"--upgrade","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"22M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}