interface-meta

1.3.0 · maintenance · verified Thu Apr 09

`interface_meta` is a Python library (current version 1.3.0) that provides a robust way to expose extensible APIs. It focuses on enforcing method signatures and ensuring consistent documentation for subclasses, making it suitable for plugin architectures. The library is currently in maintenance, with its last release in April 2022.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining an interface using `InterfaceMeta` with abstract properties and methods, and then creating a conforming implementation. It highlights how to set interface-specific configurations for method signature enforcement and documentation.

from abc import abstractproperty
from interface_meta import InterfaceMeta

class MyInterface(metaclass=InterfaceMeta):
    """An example interface."""

    INTERFACE_EXPLICIT_OVERRIDES = True
    INTERFACE_RAISE_ON_VIOLATION = False
    INTERFACE_SKIPPED_NAMES = {'__init__'}

    def __init__(self):
        """MyInterface constructor."""
        pass

    @abstractproperty
    def name(self):
        """A descriptive name."""
        raise NotImplementedError

    def say_hello(self):
        """Say hello."""
        return f"Hello, I am {self.name}!"

class MyImplementation(MyInterface):
    def __init__(self):
        super().__init__()
        self._name = "My Implementation"

    @property
    def name(self):
        return self._name

# Example usage:
instance = MyImplementation()
print(instance.say_hello())
print(f"Instance name: {instance.name}")

view raw JSON →