{"id":5165,"library":"crcmod-plus","title":"CRCmod-plus","description":"crcmod-plus is a modernized Python package for generating objects that compute the Cyclic Redundancy Check (CRC). It is a drop-in replacement for the original `crcmod` 1.7 package, having dropped Python 2 support and updated the build pipeline for modern Python environments. It enables the use of any 8, 16, 24, 32, or 64-bit CRC, allowing users to specify custom polynomials or utilize a variety of predefined CRC algorithms. The library maintains a moderate release cadence, primarily focusing on Python compatibility and minor enhancements.","status":"active","version":"2.3.1","language":"en","source_language":"en","source_url":"https://github.com/ntamas/crcmod-plus","tags":["crc","checksum","data integrity","cryptography","crcmod"],"install":[{"cmd":"pip install crcmod-plus","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"mkCrcFun","correct":"import crcmod\ncrc_func = crcmod.mkCrcFun(...)"},{"symbol":"Crc","correct":"import crcmod\ncrc_obj = crcmod.Crc(...)"},{"note":"Predefined CRC functions are in the `crcmod.predefined` submodule, not directly under `crcmod`.","wrong":"import crcmod\npredefined_crc_func = crcmod.mkPredefinedCrcFun('crc-32')","symbol":"mkPredefinedCrcFun","correct":"import crcmod.predefined\npredefined_crc_func = crcmod.predefined.mkPredefinedCrcFun('crc-32')"},{"note":"The `PredefinedCrc` class is in the `crcmod.predefined` submodule, not directly under `crcmod`.","wrong":"import crcmod\npredefined_crc_obj = crcmod.PredefinedCrc('crc-32')","symbol":"PredefinedCrc","correct":"import crcmod.predefined\npredefined_crc_obj = crcmod.predefined.PredefinedCrc('crc-32')"}],"quickstart":{"code":"import crcmod\nimport crcmod.predefined\n\n# --- Custom CRC-32 calculation ---\n# Create a CRC function using a custom polynomial (e.g., CRC-32-ISO-HDLC)\ncrc32_func_custom = crcmod.mkCrcFun(0x104C11DB7, initCrc=0, xorOut=0xFFFFFFFF)\ndata_bytes = b\"123456789\"\ncrc_value_custom = crc32_func_custom(data_bytes)\nprint(f\"Custom CRC-32 for '123456789': {hex(crc_value_custom)}\")\n\n# Alternatively, use the Crc class for a stateful calculator\ncrc32_obj_custom = crcmod.Crc(0x104C11DB7, initCrc=0, xorOut=0xFFFFFFFF)\ncrc32_obj_custom.update(b\"123\")\ncrc32_obj_custom.update(b\"456789\")\nprint(f\"Custom CRC-32 (Crc class) for '123456789': {hex(crc32_obj_custom.crcValue)}\")\n\n# --- Predefined CRC-16 (XMODEM) calculation ---\n# Create a CRC function using a predefined algorithm name\ncrc16_func_xmodem = crcmod.predefined.mkCrcFun('xmodem')\ncrc_value_xmodem = crc16_func_xmodem(data_bytes)\nprint(f\"Predefined CRC-16 (XMODEM) for '123456789': {hex(crc_value_xmodem)}\")\n\n# Alternatively, use the PredefinedCrc class\ncrc16_obj_xmodem = crcmod.predefined.PredefinedCrc('xmodem')\ncrc16_obj_xmodem.update(data_bytes)\nprint(f\"Predefined CRC-16 (XMODEM, PredefinedCrc class) for '123456789': {hex(crc16_obj_xmodem.crcValue)}\")","lang":"python","description":"This quickstart demonstrates how to calculate CRCs using both custom polynomials via `crcmod.mkCrcFun` and `crcmod.Crc` class, and predefined algorithms via `crcmod.predefined.mkCrcFun` and `crcmod.predefined.PredefinedCrc` class."},"warnings":[{"fix":"Upgrade to Python 3.9+ and install `crcmod-plus`.","message":"crcmod-plus dropped support for Python 2.x. If migrating from the original `crcmod` 1.7, ensure your environment is Python 3.9 or newer.","severity":"breaking","affected_versions":"<2.0.0 (original `crcmod`) -> 2.0.0+"},{"fix":"Ensure all input data is encoded to `bytes` (e.g., `my_string.encode('utf-8')`) before passing it to CRC functions.","message":"CRC functions and classes in `crcmod-plus` (and `crcmod`) expect byte strings (`bytes`) as input for Python 3.x. Passing Unicode strings (`str`) will result in a TypeError.","severity":"gotcha","affected_versions":"2.0.0+"},{"fix":"Always use `pip install crcmod-plus` to ensure you are getting the actively maintained and Python 3.9+ compatible version.","message":"While `crcmod-plus` is a drop-in replacement for `crcmod` 1.7, it is a distinct package. Users should explicitly install `crcmod-plus` for the modernized, Python 3-compatible version, as the original `crcmod` on PyPI is old and unmaintained.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `import crcmod.predefined` when intending to use predefined CRC algorithms or classes.","message":"The `crcmod.predefined` module, which contains standard CRC algorithms, needs to be explicitly imported (e.g., `import crcmod.predefined`). Symbols like `mkPredefinedCrcFun` are not directly available under `import crcmod`.","severity":"gotcha","affected_versions":"All versions, especially before 2.3.1 if relying on implicit side-effects"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}