2025-07-08

In Python, a protocol specifies the methods and attributes that a class must implement to be considered of a given type. Protocols are important in Python’s type hint system, which allows for static type checking through external tools, such as mypy, Pyright, and Pyre.

Before there were protocols, these tools could only check for nominal subtyping based on inheritance. There was no way to check for structural subtyping, which relies on the internal structure of classes. This limitation affected Python’s duck typing system, which allows you to use objects without considering their nominal types. Protocols overcome this limitation, making static duck typing possible.

In this video course, you’ll:

Gain clarity around the use of the term protocol in Python

Learn how type hints facilitate static type checking

Learn how protocols allow static duck typing

Create custom protocols with the Protocol class

Understand the differences between protocols and abstract base classes

[ Improve Your Python With � Python Tricks � – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Show more