← All notes

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

Claims

Sources

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.

License: CC-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.

Cite this

Permanent ID: iil:note:c2xk2nv1

iinventedlight. 2026. "Python collections.abc: test container interfaces with ABCs." iinventedlight Library, iil:note:c2xk2nv1, version of 2026-11-23. https://iinventedlight.com/library/notes/python-collections-abc/. License: CC-BY-4.0.

@misc{iil_note_c2xk2nv1,
  author = {{iinventedlight}},
  title = {{Python collections.abc: test container interfaces with ABCs}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/python-collections-abc/},
  note = {Permanent ID iil:note:c2xk2nv1. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-collections-abc.md.