python-registrable
Python module for registering and instantiating classes by name. Based on the implementation from AllenNLP.
Installing
The quickest way to install is through PyPI.
pip install registrable
Usage
from registrable import Registrable
class MyBaseClass(Registrable):
def do_something(self):
raise NotImplementedError
@MyBaseClass.register("first_implementation")
class FirstImplementation(MyBaseClass):
def do_something(self):
return 1
subclass = MyBaseClass.by_name("first_implementation")
instance = subclass()
assert instance.do_something() == 1