Python Binascii Module

Anonymous contributor's avatar
Anonymous contributor
Published Oct 25, 2023
Contribute to Docs

The binascii module contains a number of methods to convert between binary and various ASCII-encoded binary representations. It is a valuable resource when dealing with binary data in various contexts, such as network protocols and file handling. Normally, a developer will not use these functions directly but use wrapper modules like uu or base64 instead. The binascii module contains low-level functions written in C for greater speed that are used by the higher-level modules. The Python binascii module is a valuable tool when working with binary data and encoding it into different text formats or decoding text representations back into binary data.

The following functions are provided by the binascii module:

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Binascii Module

.a2b_base64()
Decodes base64 encoded data back into its original binary representation.
.a2b_hex()
Decodes a hexadecimal (base-16) encoded ASCII string into the original binary data (bytes).
.a2b_qp()
Decodes a string of quoted-printable data back to binary.
.a2b_uu()
Returns a new object containing the decoded binary data from ASCII-encoded data in the UUEncode format.
.b2a_base64()
Converts binary data into a Base64-encoded ASCII string.
.b2a_hex()
Converts binary data to a bytes object containing its hexadecimal (Base16) ASCII representation.
.b2a_qp()
Converts binary data into a bytes object containing its quoted-printable ASCII representation.
.b2a_uu()
Converts binary data into a bytes object containing a string of ASCII characters in UUEncoded format.
.crc32()
Computes the CRC-32 checksum of binary data using a cyclic redundancy check algorithm.
.crc_hqx()
Computes a 16-bit CRC (CRC-CCITT) checksum of binary data using the CRC-HQX algorithm.
.hexlify()
Encodes binary data into a hexadecimal (base-16) representation.
.unhexlify()
Converts a hexadecimal string into its binary (bytes) representation.

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours