---
source: https://iinventedlight.com/library/notes/python-collections-abc.md
title: "Python collections.abc: test container interfaces with ABCs"
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, collections.abc — Abstract Base Classes for Containers; CPython, collections.abc 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-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). 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-collections-abc"
tags: [python, collections, abc, interfaces, isinstance]
client: Librarian
sources:
  - id: S1
    title: "collections.abc — Abstract Base Classes for Containers"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/collections.abc.html
    accessed: 2026-11-23
    license: "PSF License Version 2"
  - id: S2
    title: "collections.abc documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/collections.abc.rst
    accessed: 2026-11-23
    license: "PSF License Version 2"
---
# Python collections.abc: test container interfaces with ABCs
**Answer:** This module provides abstract base classes used to test whether a class provides a particular interface. Examples include hashable types and mappings. Existing classes can be registered as virtual subclasses of the ABCs.

## Testing an interface

Abstract base classes in this module can be used to test whether a class provides a particular interface.

Examples include whether a type is hashable, and whether it is a mapping.

A newly written class can inherit directly from one of these abstract base classes.

Added in version 3.3: formerly, this module was part of the collections module.

## Virtual subclasses

Existing classes and built-in classes can be registered as virtual subclasses of the ABCs.

Users can then rely on issubclass or isinstance tests to determine whether the full interface is supported.

Registered classes should define the full API, including the abstract methods and the mixin methods.

Methods that are automatically inferred from the rest of the API are the exception to this rule.

## See also

- [python-abc](https://iinventedlight.com/library/notes/python-abc/)
- [python-collections-containers](https://iinventedlight.com/library/notes/python-collections-containers/)
- [python-types](https://iinventedlight.com/library/notes/python-types/)

## Claims

- id: C1
  claim: The ABCs test whether a class provides a particular interface.
  source: S1
  evidence: "test whether a class provides a particular interface"

- id: C2
  claim: Examples include whether a type is hashable or a mapping.
  source: S1
  evidence: "whether it is hashable or whether it is a mapping"

- id: C3
  claim: Existing classes can be registered as virtual subclasses of the ABCs.
  source: S2
  evidence: "registered as \"virtual subclasses\" of the ABCs"

- id: C4
  claim: Registered classes should define the full API.
  source: S2
  evidence: "define the full API including all of the abstract methods"

## Sources

- [S1] collections.abc — Abstract Base Classes for Containers. Python Software Foundation. https://docs.python.org/3/library/collections.abc.html . License: PSF License Version 2. Accessed 2026-11-23.

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

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, collections.abc — Abstract Base Classes for Containers; CPython, collections.abc 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).
