Loosely coupled, ABC based, Python Interface Registry
visage is a small project providing a registry for loose coupling of interfaces and implementations.
visage is heavily based on Python’s abstract base classes for allowing isinstance checks in the presence of an interface definition. However, in the absence of an interface definition, registry-level checks can be performed in order to evaluate a given implementation’s declaration of interface support.
import abc import visage.lib @visage.lib.interface('company.com/interface/Shapes') class Interface(metaclass=abc.ABCMeta): pass @visage.lib.implementation('company.com/interface/Shapes') class Implementation(object): pass Instance = Implementation() assert visage.lib.isinstance(Instance, 'company.com/interface/Shapes') assert visage.lib.hasinterface(Implementation, 'company.com/interface/Shapes') assert visage.lib.isdefinition(Interface, 'company.com/interface/Shapes')
However, the declaration of the interface is not necessary for an implementation to be declared. Implementations are fully functional without an interface, and identifier based checks can be easily used.
When the Interface object is present, it can be used to do checks using the builtins that work with classes:
assert isinstance(Instance, Interface) assert issubclass(Implementation, Interface)
- Registry Queries for Selecting Implementation classes based on quals.
- IID-to-module mappings for IID based imports.
- Adaption capabilities?