---
title: "crc | pypx"
description: "Pure Python CRC library"
canonical_url: "https://pypx.app/packages/crc"
meta:
  "og:description": "Pure Python CRC library"
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_crc%2Cversion_8.0.0%2Csummary_Pure%2BPython%2BCRC%2Blibrary%2Clicense_BSD-2-Clause%2Cp_Ii9wYWNrYWdlcy9jcmMi%2Cs_u6Yo-WUCZAjj_1Yu.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "crc 8.0.0"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_crc%2Cversion_8.0.0%2Csummary_Pure%2BPython%2BCRC%2Blibrary%2Clicense_BSD-2-Clause%2Cp_Ii9wYWNrYWdlcy9jcmMi%2Cs_u6Yo-WUCZAjj_1Yu.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **crc**

v8.0.0

Pure Python CRC library

9 KB Python 3.11+ py3-none-anyBSD-2-Clause

[**Diff **](https://pypx.app/packages/crc/diff)

`$ uv add crc`

Calculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations

---

- Documentation: https://nicoretti.github.io/crc
- Source Code: https://github.com/Nicoretti/crc

---

## Available CRC Configurations

For convenience various frequently used crc configurations ship with the library out of the box.

| CRC8 | CRC16 | CRC32 | CRC64 |
| --- | --- | --- | --- |
| CCITT | XMODEM | CRC32 | CRC64 |
| AUTOSAR | GSM | AUTOSAR | |
| SAEJ1850 | PROFIBUS | BZIP2 | |
| SAEJ1850\_ZERO | MODBUS | POSIX | |
| BLUETOOTH | IBM-3740 |  | |
| MAXIM-DOW | KERMIT |  | |

If you find yourself in the position, where having a new configuration available out of the box would be desirable, feel free to create a [PR](https://github.com/Nicoretti/crc/pulls) or file an [issue](https://github.com/Nicoretti/crc/issues).

## Custom Configurations

If you want to create a custom configuration, you should have the following information available:

🗒 Note:

```
This library currently only supports bit widths of full bytes 8, 16, 24, 32, ...
```

- **width**
- **polynom**
- **init value**
- **final xor value**
- **reversed input**
- **reversed output**

In case you only have a name of a specific crc configuration/algorithm and you are unsure what are the specific parameters of it, a look into this [crc-catalogue](http://reveng.sourceforge.net/crc-catalogue/all.htm) might help.

## Requirements

- [>= Python 3.8](https://www.python.org)

## Installation

```
pip install crc
```

## Examples

### Create a Calculator

#### Pre defined configuration

```
from crc import Calculator, Crc8

calculator = Calculator(Crc8.CCITT)
```

#### Custom configuration

```
from crc import Calculator, Configuration

config = Configuration(
    width=8,
    polynomial=0x07,
    init_value=0x00,
    final_xor_value=0x00,
    reverse_input=False,
    reverse_output=False,
)

calculator = Calculator(config)
```

### Calculate a checksum

#### Standard

```
from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT)

assert expected == calculator.checksum(data)
```

#### Optimized for speed

```
from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT, optimized=True)

assert expected == calculator.checksum(data)
```

### Verify a checksum

#### Standard

```
from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT)

assert calculator.verify(data, expected)
```

#### Optimized for speed

```
from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT, optimized=True)

assert calculator.verify(data, expected)
```

### Calculate a checksum with raw registers

#### Register

```
from crc import Crc8, Register

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
register = Register(Crc8.CCITT)

register.init()
register.update(data)
assert expected == register.digest()
```

#### TableBasedRegister

```
from crc import Crc8, TableBasedRegister

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
register = TableBasedRegister(Crc8.CCITT)

register.init()
register.update(data)
assert expected == register.digest()
```

## References & Resources

- [A Painless guide to crc error detection algorithms](http://www.zlib.net/crc_v3.txt)
- [CRC-Catalogue](http://reveng.sourceforge.net/crc-catalogue/all.htm)

## **Details **

<dl>

<dt>Version</dt>
<dd>8.0.0</dd>

<dt>License</dt>
<dd>BSD-2-Clause</dd>

<dt>Python</dt>
<dd>&lt;4.0,&gt;=3.11</dd>

<dt>Maintainer</dt>
<dd>Nicola Coretti &lt;nico.coretti@gmail.com&gt;</dd></dl>

## **Links**

- [Changelog](https://nicoretti.github.io/crc/changelog/unreleased/)
- [Documentation](https://nicoretti.github.io/crc/)
- [Homepage](https://nicoretti.github.io/crc/)
- [Issues](https://github.com/Nicoretti/crc/issues)
- [Repository](https://github.com/Nicoretti/crc)
- [Source](https://github.com/Nicoretti/crc)
- [View on PyPI](https://pypi.org/project/crc/)

## **Release Cadence **

**1**

releases in the past year

avg 94 days between releases

## **Maintainers **

- Nicola Coretti · [nico.coretti@gmail.com](mailto:nico.coretti@gmail.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/crc#webpage","@type":"WebPage","description":"Pure Python CRC library","name":"crc","url":"https://pypx.app/packages/crc","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/crc"]}]},{"@id":"https://pypx.app/packages/crc#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"Pure Python CRC library","license":"BSD-2-Clause","name":"crc","softwareVersion":"8.0.0"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
