Protocols in Python

How to use structural subtyping

Oliver S
Towards Data Science
5 min readJul 27, 2023

--

Python 3.8 introduced a neat new feature: protocols. Protocols are an alternative to abstract base classes (ABC), and allow structural subtyping — checking whether two classes are compatible based on available attributes and functions alone. In this post we’ll go into the details about this and show how to use protocols using practical examples.

Photo by Chris Liverani on Unsplash

--

--