Python Protocols and Structural Subtyping for Flexible APIs
Python code often depends on behavior rather than a specific class hierarchy. A function may only need an object with a send() method, a read() method, or a pair of repository operations.
typing.Protocol lets type checkers describe those behavioral requirements directly. A class satisfies a protocol by having compatible members; it does not need to inherit from the protocol.
This is structural subtyping: “if it has the required shape, it can be used here.”