Skip to main content

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

Metadata

Release files for registrable 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for registrable 0.0.4
File Size Uploaded
registrable-0.0.4.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for registrable 0.0.4
File Interpreter ABI Platform
registrable-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / registrable-0.0.4.tar.gz

Download URL registrable-0.0.4.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
20bb42aeeab062432f053a788c775106e45a2fab1fdae4103df45e465086d0a3
BLAKE2b-256 checksum
How to use checksums
ba57e7a9c28426a7bcd411a77885a633de468430f1f479c043deb1254ba1da02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Release files / registrable-0.0.4-py3-none-any.whl

Download URL registrable-0.0.4-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
475ec762101c50942f59d15256646162c497e91e6ecd1442ad9b34ada113f73c
BLAKE2b-256 checksum
How to use checksums
8a476370d9389664f1af31de4048934faeb681035a079ddc3d284a366875e755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page