On this page
  1. quopri
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Streaming Large Payloads and Header Mode
  7. Gotchas & Boundaries
  8. Common Functions

quopri

Prev: queue | Up: stdlib_module | Next: random
Rel: email, json, mailbox, mimetypes, base64
Ref: docs.python.org — quopri
Tags: #public #python3 #stdlib


Import

import quopri

Overview

Encoder and decoder for MIME Quoted-Printable transfer encoding (RFC 1521/2045), which keeps mostly-ASCII text human-readable while escaping non-ASCII or control bytes as =XX hex pairs. Use quopri when working directly with low-level email or MIME payloads (though high-level email.message.EmailMessage usually handles this automatically).

Quick Start

import quopri

raw = "Café = 100%".encode("utf-8")
encoded = quopri.encodestring(raw)
assert b"=C3=A9" in encoded and b"=3D" in encoded
assert quopri.decodestring(encoded) == raw

Implementation Walkthrough

1. Streaming Large Payloads and Header Mode

encode(inp, out, quotetabs) and decode(inp, out) stream binary file-like objects, and header=True encodes spaces as underscores (_) per RFC 2047 header rules:

import io
import quopri

src = io.BytesIO(b"hello world\t!")
dst = io.BytesIO()
quopri.encode(src, dst, quotetabs=True)

assert dst.getvalue() == b"hello world=09!"
assert quopri.encodestring(b"a b", header=True) == b"a_b"

Gotchas & Boundaries

Common Functions

Linked from

Related notes