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
# 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)
| File | Size | Uploaded | |
|---|---|---|---|
| registrable-0.0.4.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|