binascii – Convert between binary and ASCII

This module implements a subset of the corresponding CPython module, as described below. For more information, please refer to the original CPython documentation: binascii

This module implements conversion (both ways) between binary data and various ASCII encodings.

Functions

binascii.hexlify(data[, sep])

Convert a string to its hexadecimal representation string.

Differences from CPython

If the additional argument sep is provided, it will be used as the separator between hexadecimal values.

Without the sep argument:

>>> binascii.hexlify('\x11\x22123')
b'1122313233'
>>> binascii.hexlify('abcdfg')
b'616263646667'

If the second argument sep is specified, it will be used to separate two hexadecimal numbers:

>>> binascii.hexlify('\x11\x22123', ' ')
b'11 22 31 32 33'
>>> binascii.hexlify('\x11\x22123', ',')
b'11,22,31,32,33'
binascii.unhexlify(data)

Convert a hexadecimal string to a binary string; the function is the opposite of hexlify.

Example:

>>> binascii.unhexlify('313233')
b'123'
binascii.a2b_base64(data)

Decode base64-encoded data, ignoring invalid characters in the input. Conforms to RFC 2045 s.6.8. Return a bytes object.

binascii.b2a_base64(data, *, newline=True)

Encode binary data in base64 format, as described in RFC 3548. If newline is True, return the encoded data followed by a newline, as a bytes object.

binascii.crc32(data[, value])

Compute the 32-bit checksum CRC-32 of the data, starting from an initial CRC value. The default initial CRC is zero. The algorithm is consistent with the ZIP file checksum.