---
source: https://iinventedlight.com/library/notes/python-email-charset.md
title: "Python email.charset: map character sets to email encodings"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-email-charset"
tags: [python, email, charset, encoding, compat32]
client: Librarian
sources:
  - id: S1
    title: "email.charset: Representing character sets"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/email.charset.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "email.charset documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.charset.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# 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

- [python-email-message](https://iinventedlight.com/library/notes/python-email-message/)
- [python-email-header](https://iinventedlight.com/library/notes/python-email-header/)
- [python-email-policy](https://iinventedlight.com/library/notes/python-email-policy/)

## 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.charset` module."

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
