Bech32m
raw JSON → 1.0.0 verified Fri May 01 auth: no python
Python library for encoding and decoding Bech32 and Bech32m addresses (Bitcoin improvement BIP-350). Version 1.0.0 supports Python 3.9+ with a stable API based on BIP-0173 and BIP-0350. Release cadence is low; maintained on GitHub.
pip install bech32m Common errors
error ModuleNotFoundError: No module named 'bech32' ↓
cause Trying to import from deprecated/nonexistent module 'bech32' after installing 'bech32m'.
fix
Install correct package: pip install bech32m and use 'from bech32m import ...'
error AttributeError: module 'bech32m' has no attribute 'encode' ↓
cause Using incorrect function name 'encode' instead of 'bech32_encode'.
fix
Use 'bech32m.bech32_encode' (or 'bech32m.bech32_decode').
Warnings
breaking The library bech32m is NOT the same as the old 'bech32' library. Import paths differ and APIs are not compatible. ↓
fix Use 'from bech32m import ...' instead of 'from bech32 import ...'. Uninstall 'bech32' if present.
gotcha The encoding functions expect data in 5-bit groups (integers 0-31). Passing raw bytes will silently produce incorrect addresses. ↓
fix Convert bytes to 5-bit groups using a conversion function (e.g., ods/bech32m provides a utility, but the main API does not include one; handle this externally).
Imports
- bech32_encode wrong
from bech32 import bech32_encodecorrectfrom bech32m import bech32_encode - bech32_decode wrong
from bech32 import bech32_decodecorrectfrom bech32m import bech32_decode
Quickstart
import os
from bech32m import bech32_encode, bech32_decode
hrp = "bc"
# Convert bytes to 5-bit groups internally
data = [0, 1, 2, 3, 4, 5]
addr = bech32_encode(hrp, data)
print("Encoded:", addr)
# Decode
hrp_got, data_got = bech32_decode(addr)
print("Decoded HRP:", hrp_got)
print("Decoded data:", data_got)