← All notes

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

Sources

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

Permanent ID: iil:note:mz2kwtqy

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.},
}

Markdown

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.

All artifact files (JSON index)

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.