Skip to main content

Python module for registering and instantiating classes by name. Based on the implementation from AllenNLP.

Project description

python-registrable

CircleCI License PyPI version Documentation Status

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

# Create a base class that inherits from `Registrable`.
class MyBaseClass(Registrable):
    def do_something(self):
        raise NotImplementedError


# Now register subclass implementations of your base class.
@MyBaseClass.register("first_implementation")
class FirstImplementation(MyBaseClass):
    def do_something(self):
        return 1


# You can access an implementation by calling `.by_name()` on the base class.
subclass = MyBaseClass.by_name("first_implementation")
instance = subclass()
assert instance.do_something() == 1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for registrable, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size registrable-0.0.4-py3-none-any.whl (9.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size registrable-0.0.4.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page