Google CRC32C

raw JSON →
1.8.0 verified Tue May 12 auth: no python install: stale quickstart: stale

A Python wrapper of the C library 'Google CRC32C', currently at version 1.8.0. It supports Python versions from 3.9 onwards and is actively maintained with regular updates.

pip install google-crc32c
error ModuleNotFoundError: No module named 'google_crc32c'
cause The `google-crc32c` package, though installed with a hyphen, is imported in Python code using an underscore (`google_crc32c`). This error occurs if the package is not installed or if Python cannot find it in the current environment.
fix
Ensure the package is installed using pip install google-crc32c and that your Python environment is correctly configured.
error ERROR: Could not build wheels for google-crc32c which use PEP 517 and cannot be installed directly
cause This error typically occurs during installation when pre-compiled wheels for your specific Python version and operating system/architecture are not available, requiring the package to be built from source. It indicates missing C build tools and development headers necessary to compile the underlying C library.
fix
Install the necessary build dependencies for your system, such as python3-dev (or python-dev), gcc, and build-essential on Linux (e.g., sudo apt-get install python3-dev gcc build-essential). For Windows, ensure you have a compatible C++ build environment, like the one provided by Visual Studio.
error As the c extension couldn't be imported, `google-crc32c` is using a pure python implementation that is significantly slower.
cause This is a `RuntimeWarning` indicating that the optimized C extension of the `google-crc32c` library failed to load, leading to a fallback to a slower pure Python implementation. This usually happens due to issues during the package's compilation or if the compiled extension cannot be found/loaded at runtime.
fix
Ensure that your system has the required C build tools and Python development headers installed (as described in the 'Could not build wheels' fix) and then try reinstalling google-crc32c.
error ImportError: cannot import name 'crc32c' from 'google_crc32c'
cause Users might incorrectly try to import a top-level `crc32c` function directly from the `google_crc32c` module. The `google-crc32c` library exposes its core functionality through `value` and `extend` functions, not a single `crc32c` function directly at the module level.
fix
Import the specific functions provided by the library, for example: from google_crc32c import value or from google_crc32c import extend to calculate CRC32C checksums.
breaking Python versions below 3.9 are not supported.
fix Upgrade Python to 3.9 or higher.
breaking The 'crc32c' object cannot be imported from 'google_crc32c', even with the correct import syntax 'from google_crc32c import crc32c'. This typically occurs when the library's C extension fails to build or load, preventing the `crc32c` function from being properly exposed by the module. A pure Python fallback might be used, but could also lead to issues if not correctly initialized.
fix Ensure your build environment contains necessary C compiler tools (e.g., 'build-base' on Alpine, 'gcc' on Debian/Ubuntu) and Python development headers (e.g., 'python3-dev' or 'python-dev'). Install these dependencies before installing `google-crc32c`. For Alpine, this often means `apk add build-base python3-dev`. If a pure Python fallback is intended, verify its implementation correctly exposes `crc32c`.
python os / libc status wheel install import disk
3.10 alpine (musl) - - - -
3.10 slim (glibc) - - - -
3.11 alpine (musl) - - - -
3.11 slim (glibc) - - - -
3.12 alpine (musl) - - - -
3.12 slim (glibc) - - - -
3.13 alpine (musl) - - - -
3.13 slim (glibc) - - - -
3.9 alpine (musl) - - - -
3.9 slim (glibc) - - - -

Calculate the CRC32C checksum of a byte string.

import os
from google_crc32c import crc32c

# Example usage
data = b'This is a test'
checksum = crc32c(data)
print('CRC32C Checksum:', checksum)