:mod:`binascii` -- Convert between binary and ASCII =================================================== .. module:: binascii :synopsis: Convert between binary and ASCII This module implements a subset of the corresponding :term:`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 --------- .. function:: hexlify(data, [sep]) Convert a string to its hexadecimal representation string. .. admonition:: Differences from CPython :class: attention 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' .. function:: unhexlify(data) Convert a hexadecimal string to a binary string; the function is the opposite of hexlify. Example:: >>> binascii.unhexlify('313233') b'123' .. function:: a2b_base64(data) Decode base64-encoded data, ignoring invalid characters in the input. Conforms to `RFC 2045 s.6.8 `_. Return a ``bytes`` object. .. function:: 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. .. function:: 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.