Python email.utils: local time, message IDs, and address helpers
Answer: The email.utils module provides a couple of useful utilities. The remaining functions are part of the legacy Compat32 email API.
Current helpers
localtime returns the local time as an aware datetime. Called with no arguments, it returns the current time. A naive datetime is treated as already local and is converted using the system zone database.
The isdst parameter was deprecated in 3.12 and removed in 3.14.
make_msgid returns a string suitable for an RFC 2822 Message-ID header. An optional idstring strengthens uniqueness, and optional domain sets the part after the at-sign, defaulting to the local hostname.
Legacy helpers
The remaining functions belong to the legacy Compat32 API.
unquote returns a copy of a string with surrounding double quotes or angle brackets removed.
Address parsers such as parseaddr and getaddresses can run in a strict mode that rejects malformed input.
See also
Claims
- id: C1 claim: localtime returns an aware datetime, or the current time if called with no arguments. source: S1 evidence: "If called without arguments, return the current time."
- id: C2 claim: make_msgid can set the domain portion after the at-sign. source: S2 evidence: "provides the portion of the msgid after the '@'."
- id: C3 claim: The remaining functions belong to the legacy Compat32 API. source: S2 evidence: "The remaining functions are part of the legacy"
Sources
- [S1] email.utils: Miscellaneous utilities. Python Software Foundation. https://docs.python.org/3/library/email.utils.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] email.utils documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.utils.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.utils: Miscellaneous utilities; CPython, email.utils 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.utils: Miscellaneous utilities; CPython, email.utils documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python email.utils: local time, message IDs, and address helpers." iinventedlight Library, iil:note:wgdck3zr, version of 2026-11-26. https://iinventedlight.com/library/notes/python-email-utils/. License: CC-BY-4.0.
@misc{iil_note_wgdck3zr,
author = {{iinventedlight}},
title = {{Python email.utils: local time, message IDs, and address helpers}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-email-utils/},
note = {Permanent ID iil:note:wgdck3zr. 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-utils.schema.json (schema; CC-BY-4.0)
- python-email-utils.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-utils.md.