Python email.parser: turn serialized messages into EmailMessage trees
Answer: email.parser turns a serialized email message into an EmailMessage object tree.
What the parser returns
The email package provides a standard parser that understands most email document structures, including MIME.
You can pass it a bytes object, a string, or a file object.
It returns the root EmailMessage instance of the object structure.
For MIME messages, that root object reports that it is multipart, and subparts are reached through payload methods.
Parser versus FeedParser
Two interfaces are available: the Parser API and the incremental FeedParser API.
Parser is most useful when the entire message is already in memory or in a file.
FeedParser fits a stream that might block waiting for more input, such as a socket.
The incremental parser only returns the root object when you close it.
Header-only parsers can be much faster, because they do not attempt to parse the message body.
See also
Claims
- id: C1 claim: The email package provides a standard parser that understands most email document structures. source: S1 evidence: "provides a standard parser that understands most email document structures"
- id: C2 claim: You can pass the parser a bytes, string, or file object. source: S1 evidence: "You can pass the parser a bytes, string or file object"
- id: C3 claim: The semantics and results of the two parser APIs are identical. source: S2 evidence: "The semantics and results of the two parser APIs are identical"
- id: C4 claim: Header-only parsers can be much faster because they do not attempt to parse the message body. source: S2 evidence: "they do not attempt to parse the message body"
Sources
- [S1] email.parser: Parsing email messages. Python Software Foundation. https://docs.python.org/3/library/email.parser.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] email.parser documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.parser.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.parser: Parsing email messages; CPython, email.parser 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.parser: Parsing email messages; CPython, email.parser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python email.parser: turn serialized messages into EmailMessage trees." iinventedlight Library, iil:note:x4dpr4vk, version of 2026-11-26. https://iinventedlight.com/library/notes/python-email-parser/. License: CC-BY-4.0.
@misc{iil_note_x4dpr4vk,
author = {{iinventedlight}},
title = {{Python email.parser: turn serialized messages into EmailMessage trees}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-email-parser/},
note = {Permanent ID iil:note:x4dpr4vk. 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-parser.schema.json (schema; CC-BY-4.0)
- python-email-parser.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-parser.md.