Python email.policy: control how the email package parses and generates messages
Answer: Policy objects let the email package change how messages are parsed and generated for different use cases.
What a policy controls
A Policy object encapsulates attributes and methods that control the behavior of email package components during use.
You can pass a policy instance into email classes and methods when you need non-default behavior.
Every class in the email package has a default policy.
Parser helpers and the Message class use the Compat32 policy, through the pre-defined compat32 instance.
EmailMessage, cloning, and future defaults
EmailMessage uses the EmailPolicy policy by default, through the pre-defined default instance.
A newly created Message or EmailMessage object takes on a policy.
When a parser creates the message, the policy passed into that parser becomes the policy of the created message.
Adding two policy objects is not commutative, so the order of the addends matters.
See also
Claims
- id: C1 claim: Policy objects exist so the email package can cover very different use cases. source: S1 evidence: "Policy objects give the email package the flexibility to handle all these disparate use cases."
- id: C2 claim: A Message or EmailMessage acquires a policy when it is created. source: S1 evidence: "When a Message or EmailMessage object is created, it acquires a policy."
- id: C3 claim: Every email package class has a default policy. source: S2 evidence: "There is a default policy used by all classes in the email package."
- id: C4 claim: Combining policies with addition is not commutative. source: S2 evidence: "This operation is not commutative"
Sources
- [S1] email.policy: Policy Objects. Python Software Foundation. https://docs.python.org/3/library/email.policy.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] email.policy documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.policy.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.policy: Policy Objects; CPython, email.policy 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.policy: Policy Objects; CPython, email.policy documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python email.policy: control how the email package parses and generates messages." iinventedlight Library, iil:note:mz2kwtqy, version of 2026-11-26. https://iinventedlight.com/library/notes/python-email-policy/. License: CC-BY-4.0.
@misc{iil_note_mz2kwtqy,
author = {{iinventedlight}},
title = {{Python email.policy: control how the email package parses and generates messages}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-email-policy/},
note = {Permanent ID iil:note:mz2kwtqy. 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-policy.schema.json (schema; CC-BY-4.0)
- python-email-policy.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-policy.md.