Python Standard Library Interfaces

The zope.interface.common package provides interfaces for objects distributed as part of the Python standard library. Importing these modules (usually) has the effect of making the standard library objects implement the correct interface.

zope.interface.common.interface

Interfaces for standard python exceptions

zope.interface.common.idatetime

Datetime interfaces.

This module is called idatetime because if it were called datetime the import of the real datetime would fail.

zope.interface.common.collections

Interface definitions paralleling the abstract base classes defined in collections.abc.

After this module is imported, the standard library types will declare that they implement the appropriate interface. While most standard library types will properly implement that interface (that is, verifyObject(ISequence, list())) will pass, for example), a few might not:

  • memoryview doesn’t feature all the defined methods of ISequence such as count; it is still declared to provide ISequence though.

  • collections.deque.pop doesn’t accept the index argument of collections.abc.MutableSequence.pop

  • range.index does not accept the start and stop arguments.

New in version 5.0.0.

zope.interface.common.numbers

Interface definitions paralleling the abstract base classes defined in numbers.

After this module is imported, the standard library types will declare that they implement the appropriate interface.

New in version 5.0.0.

zope.interface.common.builtins

Interface definitions for builtin types.

After this module is imported, the standard library types will declare that they implement the appropriate interface.

New in version 5.0.0.

zope.interface.common.io

Interface definitions paralleling the abstract base classes defined in io.

After this module is imported, the standard library types will declare that they implement the appropriate interface.

New in version 5.0.0.

zope.interface.common.mapping

Mapping Interfaces.

Importing this module does not mark any standard classes as implementing any of these interfaces.

While this module is not deprecated, new code should generally use zope.interface.common.collections, specifically IMapping and IMutableMapping. This module is occasionally useful for its extremely fine grained breakdown of interfaces.

The standard library dict and collections.UserDict implement IMutableMapping, but do not implement any of the interfaces in this module.

zope.interface.common.sequence

Sequence Interfaces

Importing this module does not mark any standard classes as implementing any of these interfaces.

While this module is not deprecated, new code should generally use zope.interface.common.collections, specifically ISequence and IMutableSequence. This module is occasionally useful for its fine-grained breakdown of interfaces.

The standard library list, tuple and collections.UserList, among others, implement ISequence or IMutableSequence but do not implement any of the interfaces in this module.