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.
pip install crcmodVerified import paths — ran on the pinned version, not inferred.
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.
Always encode strings to bytes before passing them to crcmod functions, e.g., `my_string.encode('utf-8')`.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.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.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.
Encode the Unicode string to bytes before passing it to the `crcmod` function, for example: `crc_function('your_string'.encode('utf-8'))`.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`.
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).
No dependency data recorded yet.