Fast CRC Checksum Library
fastcrc is a hyper-fast Python module for computing CRC (Cyclic Redundancy Check) checksums across 8, 16, 32, and 64-bit standards. It leverages highly optimized Rust code for performance. The current version is 0.3.5, and it maintains an active release cadence with several updates per year, focusing on performance, platform support, and new CRC algorithms.
Warnings
- breaking Support for Python 3.6 was dropped in version 0.3.0. Users on Python 3.6 must use an older version of fastcrc.
- deprecated The functions `fastcrc.crc16.ibm_refin` and `fastcrc.crc32.reversed_reciprocal_refin` were introduced as experimental in v0.2.1 and may be removed in future releases without further notice.
- gotcha All CRC functions in `fastcrc` expect bytes-like objects as input data. Passing other types (e.g., string) will result in a TypeError.
- gotcha Version 0.2.0 introduced an `initial` optional parameter to all CRC functions, allowing for chained CRC calculations. If migrating from older versions, ensure you are aware of this parameter for multi-part data processing.
Install
-
pip install fastcrc
Imports
- crc8
from fastcrc import crc8
- crc16
from fastcrc import crc16
- crc32
from fastcrc import crc32
- crc64
from fastcrc import crc64
Quickstart
from fastcrc import crc8, crc16, crc32, crc64
data = b"123456789"
# Compute CRC-8 using the cdma2000 algorithm
print(f"crc8 checksum with cdma2000 algorithm: {crc8.cdma2000(data)}")
# Compute CRC-16 using the xmodem algorithm
print(f"crc16 checksum with xmodem algorithm: {crc16.xmodem(data)}")
# Compute CRC-32 using the aixm algorithm
print(f"crc32 checksum with aixm algorithm: {crc32.aixm(data)}")
# Compute CRC-64 using the ecma_182 algorithm
print(f"crc64 checksum with ecma_182 algorithm: {crc64.ecma_182(data)}")
# Chained CRC calculation with initial data
initial_crc = crc16.xmodem(b'1234')
final_crc = crc16.xmodem(b'56789', initial_crc)
print(f"crc16 checksum with xmodem algorithm (chained): {final_crc}")