# Protocol
A protocol is a [[Contract|contract]], that describes a set of [[Attribute|attributes]] and [[Method|methods]] that any [[Class|classes]] or [[Object|objects]] must possess to be considered Protocol compliant. Protocols are a tool for doing [[Structural Typing]].
A [[class]] or [[object]] doesn't need to inherit of a protocol, it should only respect the [[contract]]
Protocol:
```python
class UserProtocol(typing.Protocol):
id: int
name: str
email: str
def get_full_info(self) -> str:
...
```
The Protocol is compatible with [[Object|objects]], [[Class|classes]] or adhoc entities.
But protocols aren't the only way to define a [[Contract|contract]]. We could use, depending the need, [[Structural Typing|structural typing]] and [[Type Annotation|type annotations]].
Is Protocol an [[Interface|interface]] ? No.
The protocol (in Python) differs from the [[Interface|interface]] (in statically typed languages like C#, Java or Typescript for example) in that the [[Object|object]] must inherit the [[Interface|interface]], whereas in Python it is sufficient for the [[Object|object]] to contain the [[Attribute|attributes]] and methods of the protocol to respect the [[Contract|contract]].
---
Bibliography:
- [Protocols - typing.readthedocs.io](https://typing.readthedocs.io/en/latest/spec/protocol.html#protocols)