all Python 3binasciiterm
binascii
module
Low-level conversions between bytes and ASCII: hex, Base64 and CRC32.
Syntax
import binascii
This is the C core under base64 and other codecs; you use it directly for hexlify/unhexlify and the crc32 checksum. For Base64 the base64 module is handier, and plain hex only needs bytes.hex and bytes.fromhex. Invalid input raises binascii.Error rather than a generic ValueError.
Examples
import binascii
print(binascii.hexlify(b'Hi')) # → b'4869'
print(binascii.unhexlify('4869')) # → b'Hi'
print(binascii.crc32(b'hello')) # → 907060870
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy