This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

interface provides facilities for declaring interfaces and for statically asserting that classes implement those interfaces.

interface improves on Python’s abc module in two ways:

  1. Interface requirements are checked at class creation time, rather than at instance creation time. This means that interface can tell you if a class fails to meet the requirements of an interface even if you never create any instances of that class.

  2. interface requires that method signatures of interface implementations are compatible with the signatures declared in the interface. For example, the following code using abc does not produce an error:

    >>> from abc import ABCMeta, abstractmethod
    >>> class Base(metaclass=ABCMeta):
    ...     @abstractmethod
    ...     def method(self, a, b):
    ...         pass
    >>> class Implementation(MyABC):
    ...     def method(self):
    ...         return "This shouldn't work."
    >>> impl = Implementation()

    The equivalent code using interface produces an error indicating that the signature of our implementation method is incompatible with the signature of our interface declaration:

    >>> from interface import implements, Interface
    >>> class I(Interface):
    ...     def method(self, a, b):
    ...         pass
    >>> class C(implements(I)):
    ...     def method(self):
    ...         return "This shouldn't work"
    class C failed to implement interface I:
    The following methods were implemented but had invalid signatures:
      - method(self) != method(self, a, b)

Defining an Interface

To define an interface, simply subclass from interface.Interface and define method stubs in your class body.

from interface import Interface

class MyInterface(Interface):

    def method1(self):

    def method2(self, arg1, arg2):

Implementing an Interface

To declare that a particular class implements an interface I, pass implements(I) as a base class for your class.

from interface import implements

class MyClass(implements(MyInterface)):

    def method1(self):
        return "method1"

    def method2(self, arg1, arg2):
        return "method2"


$ pip install python-interface
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
python-interface-1.0.0.tar.gz (9.4 kB) Copy SHA256 Checksum SHA256 Source Aug 5, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting