---
source: https://iinventedlight.com/library/notes/python-marshal.md
title: "Python marshal: a Python-specific binary format"
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, marshal — Internal Python object serialization; CPython, marshal 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-25
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-25
as_of: 2026-11-25
confidence: medium
untested: "Not reproduced (2026-11-25). 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-marshal"
tags: [python, marshal, pyc, serialization, pickle]
client: Librarian
sources:
  - id: S1
    title: "marshal — Internal Python object serialization"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/marshal.html
    accessed: 2026-11-25
    license: "PSF License Version 2"
  - id: S2
    title: "marshal documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/marshal.rst
    accessed: 2026-11-25
    license: "PSF License Version 2"
---
# Python marshal: a Python-specific binary format
**Answer:** The marshal module reads and writes Python values in a binary format.

## What the format is for

Architecture issues do not affect the format, even though the format is specific to Python.

Format details stay undocumented on purpose.

Between Python versions the format may change, although it rarely does.

It is not a general persistence module.

## When to use pickle instead

Reading and writing pseudo-compiled code for .pyc files is the main reason the module exists.

For serializing Python objects, use the pickle module instead.

Erroneous or maliciously constructed data is not something the module is intended to be secure against.

## See also

- [python-pickle](https://iinventedlight.com/library/notes/python-pickle/)
- [python-shelve](https://iinventedlight.com/library/notes/python-shelve/)
- [python-struct](https://iinventedlight.com/library/notes/python-struct/)

## Claims

- id: C1
  claim: The module reads and writes Python values in a binary format.
  source: S1
  evidence: "This module contains functions that can read and write Python values"

- id: C2
  claim: The format details are undocumented on purpose.
  source: S1
  evidence: "Details of the format are undocumented on purpose"

- id: C3
  claim: The module reads and writes Python values in a binary format.
  source: S2
  evidence: "This module contains functions that can read and write Python values"

- id: C4
  claim: The format details are undocumented on purpose.
  source: S2
  evidence: "Details of the format are undocumented on purpose"

## Sources

- [S1] marshal — Internal Python object serialization. Python Software Foundation. https://docs.python.org/3/library/marshal.html . License: PSF License Version 2. Accessed 2026-11-25.

- [S2] marshal documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/marshal.rst . License: PSF License Version 2. Accessed 2026-11-25.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, marshal — Internal Python object serialization; CPython, marshal 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).
