Python’s Native Protocols

The only validation for these is by EAFP (duck-typing).

Many are now encapsulated by ABCs:

http://docs.python.org/dev/library/collections.abc.html

Most of these are invoked in a special way when using builtins:

http://docs.python.org/dev/reference/datamodel.html#special-method-names

http://www.google.com/search?domains=www.python.org&sitesearch=www.python.org&sourceid=google-search&q=protocol&submit=search

Thread: [Python-ideas] __iter__ implies __contains__ | http://mail.python.org/pipermail/python-ideas/2011-October/012023.html | http://mail.python.org/pipermail/python-ideas/2011-October/012029.html | http://mail.python.org/pipermail/python-ideas/2011-October/012037.html | http://mail.python.org/pipermail/python-ideas/2011-October/012043.html | http://mail.python.org/pipermail/python-ideas/2011-October/012050.html | http://mail.python.org/pipermail/python-ideas/2011-October/012053.html | http://mail.python.org/pipermail/python-ideas/2011-October/012055.html | http://mail.python.org/pipermail/python-ideas/2011-October/012061.html

object protocol

http://docs.python.org/reference/datamodel.html#basic-customization

object.__new__(cls[, ...])
object.__init__([...])
object.__del__()

str protocol

http://docs.python.org/reference/datamodel.html#basic-customization

object.__str__()
object.__unicode__()

comparison protocol

http://docs.python.org/reference/datamodel.html#basic-customization

object.__lt__(other)
object.__le__(other)
object.__eq__(other)
object.__ne__(other)
object.__gt__(other)
object.__ge__(other)

object.__cmp__(other)

attribute access protocol

http://docs.python.org/reference/datamodel.html#customizing-attribute-access

object.__getattribute__(name)
object.__getattr__(name)
object.__setattr__(name, value)
object.__delattr__(name)

descriptor protocol

http://docs.python.org/reference/datamodel.html#implementing-descriptors

object.__get__(obj, cls)
object.__set__(obj, value)
object.__delete__(obj)

type protocol

http://docs.python.org/reference/datamodel.html#customizing-instance-and-subclass-checks

class.__instancecheck__(obj)
class.__subclasscheck__(cls)

sequence protocol

http://docs.python.org/reference/datamodel.html#emulating-container-types

object.__len__()
object.__getitem__(key)
object.__setitem__(key, value)
object.__delitem__(key)
object.__reversed__()
object.__contains__(obj)
object.__getslice__(i, j)
object.__setslice__(i, j, value)
object.__delslice__(i, j)

old-style iteration protocol

object.__len__()
object.__getitem__(key)

iterator protocol

object.__iter__()

iterable protocol

http://docs.python.org/library/stdtypes.html#typeiter

object.next()
object.__iter__()

context manager protocol

http://docs.python.org/reference/datamodel.html#with-statement-context-managers

object.__enter__()
object.__exit__(exc_type, exc_value, traceback)

file protocol

pickle protocol

http://docs.python.org/library/pickle.html#the-pickle-protocol

object.__getinitargs__()
object.__getnewargs__()
object.__getstate__()
object.__setstate__(state)
object.__reduce__()
object.__reduce_ex__(protocol)

buffer protocol

Python Database API (PEP 249)

http://www.python.org/dev/peps/pep-0249/