protocol

The term protocol carries two subtly different meanings. The first meaning refers to internal protocols, such as the iterator, context manager, and descriptor protocols.

These protocols are widely understood within the community and consist of magic or special methods that make up a given protocol. For example, the .__iter__() and .__next__() methods define the iterator protocol.

Python 3.8 introduced a second, slightly different type of protocol. These protocols specify the methods and attributes that a class must implement to be considered of a given type.

These protocols are part of Python’s type-hinting system and are defined in the typing module.

Tutorial

Python Protocols: Leveraging Structural Subtyping

In this tutorial, you'll learn about Python's protocols and how they can help you get the most out of using Python's type hint system and static type checkers.

intermediate python

For additional information on related topics, take a look at the following resources:


By Dan Bader • Updated Sept. 25, 2025