Python email.charset: map character sets to email encodings
Answer: This module provides a Charset class for representing character sets and character set conversions in email messages, plus a character set registry.
Legacy status and the Charset class
This is a legacy Compat32 email API module. The new API uses only the aliases table.
The remaining text in this section is the original documentation of the module.
Import this class from the email.charset module.
Instances of Charset are used in several other modules within the email package.
Charset maps character sets to their email properties. Optional input_charset is always coerced to lower case.
Common aliases are converted to their official email names. latin_1 is converted to iso-8859-1. Defaults to 7-bit us-ascii.
Header and body encodings
Some character sets, in email headers or bodies, must be encoded with quoted-printable or base64.
Certain character sets must be converted outright, and are not allowed in email.
header_encoding may be set to QP, BASE64, or SHORTEST, for the shortest of QP or BASE64.
body_encoding is the mail message body encoding, and it may differ from the header encoding.
SHORTEST is not allowed for body_encoding.
get_body_encoding() returns quoted-printable for QP, base64 for BASE64, and 7bit otherwise.
If no conversion codec is necessary, input_codec will be None.
See also
Claims
- id: C1 claim: The module is part of the older Compat32 email API. source: S1 evidence: "This module is part of the legacy ( Compat32 ) email API."
- id: C2 claim: SHORTEST is not a legal value for body_encoding. source: S1 evidence: "charset.SHORTEST is not allowed for body_encoding ."
- id: C3 claim: Import the class from the email.charset module. source: S2 evidence: "Import this class from the :mod:
!email.charsetmodule."
Sources
- [S1] email.charset: Representing character sets. Python Software Foundation. https://docs.python.org/3/library/email.charset.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] email.charset documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.charset.rst . License: PSF License Version 2. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, email.charset: Representing character sets; CPython, email.charset documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, email.charset: Representing character sets; CPython, email.charset documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python email.charset: map character sets to email encodings." iinventedlight Library, iil:note:1xg0z907, version of 2026-11-26. https://iinventedlight.com/library/notes/python-email-charset/. License: CC-BY-4.0.
@misc{iil_note_1xg0z907,
author = {{iinventedlight}},
title = {{Python email.charset: map character sets to email encodings}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-email-charset/},
note = {Permanent ID iil:note:1xg0z907. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-email-charset.schema.json (schema; CC-BY-4.0)
- python-email-charset.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-email-charset.md.