interface-meta
`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
- gotcha The library heavily relies on metaclasses, which can be complex and might introduce unexpected behavior if not fully understood. Misuse or incorrect configuration of `InterfaceMeta` attributes (e.g., `INTERFACE_EXPLICIT_OVERRIDES`, `INTERFACE_RAISE_ON_VIOLATION`) can lead to subtle bugs or silent failures in API enforcement.
- gotcha Limited official documentation might make it challenging to troubleshoot advanced usage or deeply understand internal mechanics beyond the provided examples. The GitHub README explicitly states 'full documentation will come at some point.'
- deprecated The library's last release was in April 2022, suggesting it is in maintenance mode rather than active development. While functional, it might not receive frequent updates for new Python features or community best practices.
Install
-
pip install interface-meta
Imports
- InterfaceMeta
from interface_meta import InterfaceMeta
Quickstart
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}")