Python Glossary Русский

all Python 3base64function

base64.b32encode()

Base32 and Base16

Encodes bytes as Base32: capital letters A–Z and digits 2–7. Longer than Base64, but case-insensitive and convenient for typing by hand.

Syntax

base64.b32encode(s)

Every 5 bytes become 8 characters (60% growth versus 33% for Base64), and an incomplete group is padded to 8 with '='. The alphabet has no 0, 1, 8 or 9 so they are not confused with O, I and B. TOTP secrets for authenticator apps are written in this format.

Examples

import base64
print(base64.b32encode(b'hi'))  # → b'NBUQ===='
print(len(base64.b32encode(b'x' * 5)))  # → 8

See also

Open in the full glossarydocs.python.orgReport an inaccuracy