---
source: https://iinventedlight.com/library/notes/python-email-contentmanager.md
title: "Python email.contentmanager: get and set MIME part content"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, email.contentmanager: Managing MIME Content; CPython, email.contentmanager documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-email-contentmanager"
tags: [python, email, contentmanager, mime, raw_data_manager]
client: Librarian
sources:
  - id: S1
    title: "email.contentmanager: Managing MIME Content"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/email.contentmanager.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "email.contentmanager documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.contentmanager.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# Python email.contentmanager: get and set MIME part content
**Answer:** ContentManager, added in 3.6, registers converters that get_content and set_content use to move data in and out of MIME parts.

## The registry

ContentManager is the base class. It provides the standard registry mechanisms to register converters between MIME content and other representations.

get_content looks up a handler function based on the mimetype of the message, calls it, and returns the result of the call.

Also add a MIME-Version header if one is not present.

To find the handler, look for keys in the registry, stopping with the first one found. If none of these keys produce a handler, raise a KeyError.

## The default manager

EmailPolicy and its derivatives provide raw_data_manager as their content_manager.

Calling get_content on a multipart message raises KeyError. The default error handler is replace.

## See also

- [python-email-message](https://iinventedlight.com/library/notes/python-email-message/)
- [python-email-policy](https://iinventedlight.com/library/notes/python-email-policy/)
- [python-email](https://iinventedlight.com/library/notes/python-email/)

## Claims

- id: C1
  claim: ContentManager is the base class for content managers.
  source: S1
  evidence: "Base class for content managers."

- id: C2
  claim: set_content adds a MIME-Version header when one is missing.
  source: S1
  evidence: "Also add a MIME-Version header if one is not present"

- id: C3
  claim: The email package currently provides one concrete content manager, raw_data_manager.
  source: S2
  evidence: "although more may be added in the future."

## Sources

- [S1] email.contentmanager: Managing MIME Content. Python Software Foundation. https://docs.python.org/3/library/email.contentmanager.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] email.contentmanager documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.contentmanager.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.contentmanager: Managing MIME Content; CPython, email.contentmanager documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
