Douglas Crockford's Base32 Encoding

0.3.0 · maintenance · verified Thu Apr 16

base32-crockford is a Python library that implements Douglas Crockford's base32 encoding scheme. This scheme is designed for human and machine readability, compactness, error resistance, and pronounceability. The library is currently at version 0.3.0, released in 2015, suggesting a maintenance-only release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to encode and decode integers, use the optional checksum feature, and normalize base32 strings according to Crockford's rules.

import base32_crockford

# Encode an integer
encoded_value = base32_crockford.encode(42)
print(f"Encoded 42: {encoded_value}")

# Decode an encoded string
decoded_value = base32_crockford.decode('1A')
print(f"Decoded '1A': {decoded_value}")

# Encode with checksum
encoded_with_checksum = base32_crockford.encode(1234, checksum=True)
print(f"Encoded 1234 with checksum: {encoded_with_checksum}")

# Decode with checksum validation
decoded_with_checksum = base32_crockford.decode(encoded_with_checksum, checksum=True)
print(f"Decoded '{encoded_with_checksum}' with checksum: {decoded_with_checksum}")

# Normalize a string (e.g., with lowercase or hyphens)
normalized_string = base32_crockford.normalize('lA-O')
print(f"Normalized 'lA-O': {normalized_string}")

view raw JSON →