---
source: https://iinventedlight.com/library/notes/python-copyreg.md
title: "Python copyreg: register pickle reduction functions for custom types"
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, copyreg — Register pickle support functions; CPython, copyreg 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-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). 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-copyreg"
tags: [python, copyreg, pickle, copy, reduction]
client: Librarian
sources:
  - id: S1
    title: "copyreg — Register pickle support functions"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/copyreg.html
    accessed: 2026-11-27
    license: "PSF License Version 2"
  - id: S2
    title: "copyreg documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/copyreg.rst
    accessed: 2026-11-27
    license: "PSF License Version 2"
---
# Python copyreg: register pickle reduction functions for custom types
**Answer:** copyreg registers reduction functions and constructors so pickle and copy can handle objects that are not ordinary classes.

## Constructors and reduction functions

The module lets you define functions used when pickling particular objects.

The pickle and copy modules call those functions when they pickle or copy the objects.

It also records constructors that are not classes, such as factory functions or class instances.

constructor(object) declares that object is a valid constructor. If the object is not callable, TypeError is raised.

pickle(type, function, constructor_ob=None) names function as the reduction function for objects of that type.

The reduction function has to return a string, or a tuple that holds two to six elements. dispatch_table describes that function interface in more detail.

constructor_ob is a legacy feature and is ignored now; if you still pass it, it must be callable.

You can also attach reduction functions on a pickler dispatch_table, or on a pickle.Pickler subclass.

## Example

The docs register pickle_c for a class C. pickle_c prints pickling a C instance and returns C, (c.a,).

After copyreg.pickle(C, pickle_c), both copy.copy(c) and pickle.dumps(c) run the registered function.

## See also

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

## Claims

- id: C1
  claim: copyreg defines functions used while pickling specific objects.
  source: S1
  evidence: "The copyreg module offers a way to define functions"

- id: C2
  claim: pickle and copy use the registered functions when pickling or copying objects.
  source: S2
  evidence: "use those functions when pickling/copying those objects"

- id: C3
  claim: constructor_ob is a legacy parameter and is now ignored.
  source: S1
  evidence: "The constructor_ob parameter is a legacy feature and is now ignored"

## Sources

- [S1] copyreg — Register pickle support functions. Python Software Foundation. https://docs.python.org/3/library/copyreg.html . License: PSF License Version 2. Accessed 2026-11-27.

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

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