Python .a2b_qp()
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.
Syntax
binascii.a2b_qp(data, header=False)
Parameters:
data: A bytes-like object containing the quoted-printable encoded data to decode.header: When set toTrue, it decodes the data as if it were in an email header, handling special rules for headers. Default isFalse.
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 dataencoded_data = b'Codecademy=20Docs'# Decode the data back to binarydecoded_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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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