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.
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Exploring Protocols in Python (Course)
- Implementing Interfaces in Python: ABCs and Protocols (Tutorial)
- Iterators and Iterables in Python: Run Efficient Iterations (Tutorial)
- Duck Typing in Python: Writing Flexible and Decoupled Code (Tutorial)
- Asynchronous Iterators and Iterables in Python (Tutorial)
- Python's Magic Methods: Leverage Their Power in Your Classes (Tutorial)
- Python Protocols: Leveraging Structural Subtyping (Quiz)
- Python Interfaces: Object-Oriented Design Principles (Course)
- Implementing Interfaces in Python: ABCs and Protocols (Quiz)
- Efficient Iterations With Python Iterators and Iterables (Course)
- Iterators and Iterables in Python: Run Efficient Iterations (Quiz)
- Getting to Know Duck Typing in Python (Course)
- Duck Typing in Python: Writing Flexible and Decoupled Code (Quiz)
- Exploring Asynchronous Iterators and Iterables (Course)
- Asynchronous Iterators and Iterables in Python (Quiz)
- Python's Magic Methods in Classes (Course)
- Python's Magic Methods: Leverage Their Power in Your Classes (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Dan Bader • Updated Oct. 7, 2026