{"id":1432,"library":"crcmod","title":"CRCmod","description":"CRCmod is a Python module for calculating Cyclic Redundancy Checks (CRCs). It provides functionality to generate custom CRC algorithms and access a wide range of predefined CRC algorithms, such as CRC-CCITT and CRC-32. The current version is 1.7. The library has a slow release cadence, with updates primarily focused on bug fixes and stability.","status":"active","version":"1.7","language":"python","source_language":"en","source_url":"https://github.com/nicoretti/python-crcmod","tags":["crc","checksum","data-integrity","utility"],"install":[{"cmd":"pip install crcmod","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"crcmod","correct":"import crcmod"},{"note":"While `crcmod.Crc` exists, `crcmod.predefined.Crc` is commonly used for standard CRC algorithms.","wrong":"from crcmod import Crc","symbol":"Crc","correct":"from crcmod.predefined import Crc"},{"note":"`mkCrcFun` is a function that *returns* a CRC calculation function, it's not a method to be called directly on the module.","wrong":"crcmod.mkCrcFun()","symbol":"mkCrcFun","correct":"from crcmod import mkCrcFun"}],"quickstart":{"code":"import crcmod\nimport crcmod.predefined\n\n# 1. Using a predefined CRC algorithm (object-oriented approach)\n# Get a CRC-16-CCITT-FALSE calculator\ncrc16_ccitt = crcmod.predefined.Crc('crc-ccitt-false')\ndata_bytes = b'Hello, world!'\ncrc16_ccitt.update(data_bytes)\nprint(f\"CRC-16-CCITT-FALSE for '{data_bytes.decode()}': {hex(crc16_ccitt.crcValue)}\")\n\n# You can reset and reuse the object\ncrc16_ccitt.reset()\ncrc16_ccitt.update(b'Another test')\nprint(f\"CRC-16-CCITT-FALSE for 'Another test': {hex(crc16_ccitt.crcValue)}\")\n\n# 2. Creating a custom CRC function (functional approach)\n# Example: CRC-32 (Ethernet) - polynomial 0x104C11DB7, initial 0xFFFFFFFF, xorOut 0xFFFFFFFF, revIn/Out True\ncrc32_func = crcmod.mkCrcFun(0x104C11DB7, initCrc=0xFFFFFFFF, xorOut=0xFFFFFFFF, rev=True)\ndata_bytes_32 = b'123456789'\nresult_32 = crc32_func(data_bytes_32)\nprint(f\"CRC-32 for '{data_bytes_32.decode()}': {hex(result_32)}\")\n\n# 3. Using a predefined CRC algorithm (functional approach)\ncrc32_predef_func = crcmod.predefined.mkCrcFun('crc-32')\nresult_predef_32 = crc32_predef_func(b'123456789')\nprint(f\"CRC-32 (predefined func) for '123456789': {hex(result_predef_32)}\")","lang":"python","description":"This quickstart demonstrates how to calculate CRCs using both predefined algorithms and custom parameters. It shows both the object-oriented approach (`Crc` objects) and the functional approach (`mkCrcFun` functions) for flexibility."},"warnings":[{"fix":"Always encode strings to bytes before passing them to crcmod functions, e.g., `my_string.encode('utf-8')`.","message":"Input data to CRC functions (e.g., `update`, `mkCrcFun`) MUST be bytes (`bytes`), not strings (`str`). Passing a Python string will result in a `TypeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `crcmod.predefined.Crc('crc-name')` for an object to update incrementally with a standard CRC. Use `crcmod.mkCrcFun(...)` or `crcmod.predefined.mkCrcFun('crc-name')` if you need a simple function that calculates the CRC of an entire byte string in one call.","message":"There are different ways to use crcmod: `crcmod.predefined.Crc` (object-oriented for standard CRCs), `crcmod.mkCrcFun` (functional for custom CRCs), and `crcmod.predefined.mkCrcFun` (functional for standard CRCs). Confusing these can lead to errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you need to restart a CRC calculation from its initial state, you must create a new `crcmod.predefined.Crc` object. For example, instead of `my_crc.reset()`, use `my_crc = crcmod.predefined.Crc('crc-name')` to get a fresh instance.","message":"`crcmod.predefined.Crc` objects, used for incremental CRC calculations, do not provide a `reset()` method. Attempting to call `reset()` will result in an `AttributeError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'-32':37 '1.7':42 'access':22 'algorithm':20,29 'bug':55 'cadenc':49 'calcul':8 'ccitt':34 'check':11 'checksum':60 'crc':19,28,33,36,59 'crc-ccitt':32 'crcmod':1,2 'crcs':12 'current':39 'custom':18 'cyclic':9 'data':62 'data-integr':61 'fix':56 'focus':53 'function':15 'generat':17 'integr':63 'librari':44 'modul':6 'predefin':27 'primarili':52 'provid':14 'python':5 'rang':25 'redund':10 'releas':48 'slow':47 'stabil':58 'updat':51 'util':64 'version':40 'wide':24","created_at":"2026-04-09T03:47:41.773453+00:00","updated_at":"2026-04-16T04:04:19.888290+00:00","problems":[{"fix":"Install the library using pip, specifying the Python version if necessary: `pip install crcmod` or `pip3 install crcmod`. Ensure your virtual environment is activated if applicable.","cause":"The `crcmod` library is not installed in the active Python environment or there is a conflict between Python 2 and Python 3 installations.","error":"ModuleNotFoundError: No module named 'crcmod'"},{"fix":"Encode the Unicode string to bytes before passing it to the `crcmod` function, for example: `crc_function('your_string'.encode('utf-8'))`.","cause":"In Python 3, `crcmod` functions expect byte strings (e.g., `b'data'`) as input, but a standard Unicode string (e.g., `'data'`) was provided.","error":"TypeError: Unicode-objects must be encoded before calculating a CRC"},{"fix":"Ensure a C compiler (e.g., `gcc`) and Python development headers (e.g., `python-dev` or `python3-devel` depending on your Python version and OS) are installed on your system, then reinstall `crcmod` using `pip install --force-reinstall crcmod`.","cause":"The C extension for `crcmod` failed to compile during installation because necessary development tools (like a C compiler and Python development headers) were missing, causing `crcmod` to fall back to its slower pure-Python implementation.","error":"CommandException: Downloading this composite object requires integrity checking with CRC32c, but your crcmod installation isn't using the module's C extension, so the hash computation will likely throttle download performance."},{"fix":"Either use a predefined CRC polynomial from `crcmod.predefined` or ensure your custom polynomial correctly represents a generator for an 8, 16, 24, 32, or 64-bit CRC (e.g., an 8-bit polynomial should be between `0x100` and `0x1FF` inclusive).","cause":"The custom polynomial provided to `crcmod.mkCrcFun` does not correspond to a valid CRC width (8, 16, 24, 32, or 64 bits), or its hexadecimal representation is incorrect for the desired bit length.","error":"ValueError: The only polynomials allowed are those that generate 8, 16, 24, 32, or 64 bit CRCs."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.7","cli_name":"","cli_version":null,"type":"library","homepage":"http://crcmod.sourceforge.net/","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/crcmod/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}