← All notes

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

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

Permanent ID: iil:note:x4dpr4vk

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

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-parser.md.