crock
Typed Crockford base32 for bytes and ints, with normalization and an optional check symbol.
The problem
Order numbers, invite codes, licence keys and short IDs get read aloud, copied by hand and typed back. Decimal is long, hexadecimal is not much shorter, and base64 mixes cases and punctuation. Crockford's base32 spells numbers with 32 symbols chosen for people: digits and upper-case letters without I, L, O and U. Decoding forgives case, reads I and L as 1 and O as 0, and ignores hyphens, and an optional check symbol catches a mistyped symbol or two swapped neighbours before the code reaches your database.
crock implements the whole scheme for integers and for arbitrary bytes, strictly: every
byte string has exactly one code (up to case, aliases and hyphens), integer codes differ
only by leading zeros, which decode as zero, and anything else is refused with a clear
error.
Install
pip install crock
Python 3.10 or newer, no dependencies.
Quick start
Integers, for IDs, order numbers and short codes:
import crock
print(crock.encode_int(1234)) # 16J
print(crock.decode_int("16j")) # 1234
print(crock.encode_int(1234, width=8, group=4)) # 0000-016J
print(crock.decode_int("0000-016J")) # 1234
Bytes, for keys, hashes and tokens. Leading zero bytes are kept:
import crock
code = crock.encode(b"\x00hello", group=4)
print(code) # 01M6-AV3C-DW
print(crock.decode(code)) # b'\x00hello'
The check symbol, for codes that people copy by hand:
import crock
code = crock.encode_int(1234, check=True)
print(code) # 16JD
print(crock.decode_int(code, check=True)) # 1234
try:
crock.decode_int("1J6D", check=True)
except crock.CrockfordError as error:
print(error) # check symbol does not match
normalize gives the canonical spelling of what someone typed, so stored codes compare
equal:
import crock
print(crock.normalize("ix-Lb-Ko")) # 1X1BK0
print(crock.normalize("16j-d", check=True)) # 16JD
The public API is six names: encode, decode, encode_int, decode_int, normalize
and CrockfordError (a ValueError). The guide
has the exact rules for each.
Why crock
These are the other Crockford base32 packages on PyPI, as published on 2026-10-22:
base32-crockford0.3.0, last released in March 2015: integers only, no type hints, and a float is truncated (encode(4.2)gives"4"). Withoutchecksum=True,decode("1U")reads the check-only symbolUas a digit and returns 68. Its own test file and seeded comparisons with its code run againstcrockin this repository; the guide lists the few places where the two differ.base32-lib1.1.1: integers only, lower-case output, and a two digit ISO 7064 checksum instead of Crockford's check symbol.crockford321.0.2: a compiled extension published only as a Linux x86-64 wheel for CPython 3.10, and its decoder does not apply the I, L and O conversions. For ASCII bytes its check symbol is the value of the bytes mod 37, wherecrockuses the value of the symbols (padding bits included), so the two write different check symbols for most byte strings; the guide explains the choice. Bytes of 0x80 and above it encodes wrongly: forb"{\xd5\xd4~"it writesFC000ZGbefore the check symbol, where the specification givesFFAX8ZG.python-ulid: Crockford base32 for 16 byte ULIDs only.
The standard library's base64.b32hexencode (Python 3.10 and newer) uses the RFC 4648
"extended hex" alphabet, which includes I, L, O and U and pads with =.
crock covers both integers and arbitrary bytes, writes and verifies the check symbol for
both, normalizes look-alikes and hyphens, runs in linear time on megabyte inputs, ships
type information checked with mypy --strict, and has no dependencies.
Documentation
License
MIT. See LICENSE.
Links
- Website: https://lianes8studio.com
- GitHub: https://github.com/JaviLianes8
- LinkedIn: https://www.linkedin.com/in/jlianes/
Metadata
Release files for crock 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crock-1.0.0.tar.gz | 39.9 kB | Without provenance | Details for crock-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crock-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for crock-1.0.0-py3-none-any.whl |
Total release size: 51.2 kB
Release files / crock-1.0.0.tar.gz
| Download URL | crock-1.0.0.tar.gz |
|---|---|
| Size | 39.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
757200362e07f1d3c609a8083b34d0998da043ef6bbfd147cbfc3a3f8fbf161e
|
|
BLAKE2b-256 checksum How to use checksums |
b68984a42c124ff302ca07a8c701b9eb5f6051beb4859e8a51416d7ecb6d81eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / crock-1.0.0-py3-none-any.whl
| Download URL | crock-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e94085fdb787d849e810522eaa5121695a9fc0083b73db04ae37130e7dd72516
|
|
BLAKE2b-256 checksum How to use checksums |
b0e93d0e4703b6a2c22a7b17c41cd9de11b80f36f9560c4f6dfe8eec7539a7f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for crock 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.