Python module for registering and instantiating classes by name. Based on the implementation from AllenNLP.
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
registrable-0.0.4.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file registrable-0.0.4.tar.gz
.
File metadata
- Download URL: registrable-0.0.4.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20bb42aeeab062432f053a788c775106e45a2fab1fdae4103df45e465086d0a3 |
|
MD5 | 128dedc4aec86abd7ab2be75dc6e2148 |
|
BLAKE2b-256 | ba57e7a9c28426a7bcd411a77885a633de468430f1f479c043deb1254ba1da02 |
File details
Details for the file registrable-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: registrable-0.0.4-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 475ec762101c50942f59d15256646162c497e91e6ecd1442ad9b34ada113f73c |
|
MD5 | de406b3068d4ad68dd85639c3ef025e2 |
|
BLAKE2b-256 | 8a476370d9389664f1af31de4048934faeb681035a079ddc3d284a366875e755 |