Python abc defines abstract base classes that cannot be instantiated until abstract methods are overridden
Answer: Create an abstract base class by deriving from the helper class ABC, and use the @abstractmethod decorator on abstract methods. A class with a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. register(subclass) registers a virtual subclass of the ABC.
Example
from abc import ABC, abstractmethod
class Store(ABC):
@abstractmethod
def get(self, key): ...
class MemStore(Store):
def get(self, key):
return None
MemStore() # ok
Store() # TypeError
Store.register(dict) # dict is now a virtual subclass
Facts
- For defining ABCs, the module provides the metaclass
ABCMeta, plus a helper classABCfor defining ABCs through inheritance. ABCis a helper class that hasABCMetaas its metaclass, so an abstract base class can be created by simply deriving fromABC.@abstractmethodis a decorator indicating abstract methods; using it requires that the class's metaclass isABCMetaor is derived from it.register(subclass)registers subclass as a "virtual subclass" of this ABC.
Origin
PEP 3119 was a proposal to add Abstract Base Class (ABC) support to Python 3000, including ABCs for containers and iterators.
See also
Claims
- id: C1 claim: ABC is a helper class with ABCMeta as its metaclass. source: S1 evidence: "A helper class that has ABCMeta as its metaclass."
- id: C2 claim: abstractmethod is a decorator indicating abstract methods. source: S1 evidence: "A decorator indicating abstract methods."
- id: C3 claim: register makes a virtual subclass. source: S1 evidence: "Register subclass as a"
- id: C4 claim: PEP 3119 proposed ABC support for Python 3000. source: S2 evidence: "This is a proposal to add Abstract Base Class (ABC) support to Python 3000."
Sources
- [S1] abc — Abstract Base Classes. Python docs (library). https://docs.python.org/3/library/abc.html . License: PSF-2.0. Accessed 2026-11-18.
- [S2] PEP 3119 – Introducing Abstract Base Classes. Python PEPs. https://peps.python.org/pep-3119/ . License: Public-Domain. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs (library), abc — Abstract Base Classes; Python PEPs, PEP 3119 – Introducing Abstract Base Classes. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Public-Domain (https://peps.python.org/pep-0001/). PEP text is placed in the public domain (some also CC0-1.0). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs (library), abc — Abstract Base Classes; Python PEPs, PEP 3119 – Introducing Abstract Base Classes. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Public-Domain (https://peps.python.org/pep-0001/). PEP text is placed in the public domain (some also CC0-1.0).
Cite this
iinventedlight. 2026. "Python abc defines abstract base classes that cannot be instantiated until abstract methods are overridden." iinventedlight Library, iil:note:ebkb7t5b, version of 2026-11-18. https://iinventedlight.com/library/notes/python-abc/. License: CC-BY-4.0.
@misc{iil_note_ebkb7t5b,
author = {{iinventedlight}},
title = {{Python abc defines abstract base classes that cannot be instantiated until abstract methods are overridden}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/python-abc/},
note = {Permanent ID iil:note:ebkb7t5b. License: CC-BY-4.0.},
}
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.
- python-abc.table.json (table; CC-BY-4.0)
- python-abc.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-abc.md.