---
source: https://iinventedlight.com/library/notes/python-email-headerregistry.md
title: "Python email.headerregistry: typed RFC 5322 header objects"
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.headerregistry: Custom Header Objects; CPython, email.headerregistry 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-headerregistry"
tags: [python, email, headerregistry, rfc5322, HeaderRegistry]
client: Librarian
sources:
  - id: S1
    title: "email.headerregistry: Custom Header Objects"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/email.headerregistry.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "email.headerregistry documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.headerregistry.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# Python email.headerregistry: typed RFC 5322 header objects
**Answer:** Headers are represented by customized subclasses of str. HeaderRegistry produces them for RFC 5322 compliant email messages.

## How headers are typed

Each header value is a customized subclass of str. Which class is used depends on the policy's header_factory at the time the header is created.

When the policy comes from EmailPolicy, HeaderRegistry produces every header, and BaseHeader is always the last base class.

A second, specialized base class is chosen from a lookup table by the header name. UnstructuredHeader is the default, and Subject is the classic example.

DateHeader follows the RFC 5322 date format and can be created from a datetime. Address headers are one of the most complex structured header types.

## Extending the registry

The email package provides an extension mechanism for applications to add their own custom header types.

BaseHeader cannot build an object on its own. A specialized class must provide a parse class method, which records any RFC defects it finds.

The defects attribute is a tuple of HeaderDefect instances. If utf8 is false, non-ASCII data is encoded with RFC 2047.

## See also

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

## Claims

- id: C1
  claim: Header values are customized subclasses of str.
  source: S1
  evidence: "Headers are represented by customized subclasses"

- id: C2
  claim: Subject is the classic unstructured header.
  source: S1
  evidence: "The classic example of an unstructured header is the Subject header."

- id: C3
  claim: The module was added in Python 3.6.
  source: S2
  evidence: "versionadded:: 3.6"

## Sources

- [S1] email.headerregistry: Custom Header Objects. Python Software Foundation. https://docs.python.org/3/library/email.headerregistry.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] email.headerregistry documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/email.headerregistry.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.headerregistry: Custom Header Objects; CPython, email.headerregistry 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).
