Python .a2b_qp()

code7138989350's avatar
Published Oct 29, 2025
Contribute to Docs

In Python, the .a2b_qp() function decodes a string of quoted-printable data back to binary.

Quoted-printable is an encoding scheme used in email messages to represent non-ASCII characters using only ASCII characters.

  • 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

Syntax

binascii.a2b_qp(data, header=False)

Parameters:

  • data: A bytes-like object containing the quoted-printable encoded data to decode.
  • header: When set to True, it decodes the data as if it were in an email header, handling special rules for headers. Default is False.

Return value:

The .a2b_qp() function returns the decoded binary data as a bytes object.

Example

This example decodes a quoted-printable encoded byte string into its original binary form:

import binascii
# Quoted-printable encoded data
encoded_data = b'Codecademy=20Docs'
# Decode the data back to binary
decoded_data = binascii.a2b_qp(encoded_data)
print(decoded_data)

This produces the following output:

b'Codecademy Docs'

Codebyte Example

This example decodes a quoted-printable encoded message body retrieved from an email:

Code
Output
Loading...

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