Everything you need to implement maintainable and easy to use registry patterns in your project.
Project description
Registerer
Everything you need to implement maintainable and easy to use registry patterns in your project.
Installation
pip install registerer
Register Classes
Register classes with the same interface, enforce the type check and enjoy the benefits of type hints:
from registerer import Registerer
class Animal:
def talk(self) -> None:
raise NotImplementedError
# create a registry that requires registered items to implement the Animal interface:
animal_registry = Registerer(Animal)
@animal_registry.register("dog")
class Dog(Animal):
def talk(self) -> None:
return "woof"
Register Functions
Register functions and benefit from the function annotations validator (optional):
from registerer import Registerer, FunctionAnnotationValidator
database_registry = Registerer(
validators=[
FunctionAnnotationValidator(annotations=[("name", str)]),
]
)
@database_registry.register("sqlite")
def sqlite_database_connection(name: str):
return f"sqlite connection {name}"
Create Custom Validators
By Creating a subclass of RegistryValidator
, you can create your own validators to check registered classes/functions if you need to.
Examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
registerer-0.2.3.tar.gz
(4.2 kB
view details)
Built Distribution
File details
Details for the file registerer-0.2.3.tar.gz
.
File metadata
- Download URL: registerer-0.2.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.4 Linux/5.17.5-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ee5346ef1a98fcda762a8bf1e7a5948f4cfdd7a3cf8cf4c2c1bcfaa8c659e74 |
|
MD5 | 52629db27af8b63528e02afcc0445abf |
|
BLAKE2b-256 | fb0ee0d26f457eced8fa7af6972ed069458f70f3e6584e9d513b4bd43cf0dcbe |
File details
Details for the file registerer-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: registerer-0.2.3-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.4 Linux/5.17.5-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7198c544d0fda53bf7ff43294c6358250f58bd9dd3cc6e1107b5b910920c9247 |
|
MD5 | f68144d68643105741e9845458b39a60 |
|
BLAKE2b-256 | 4815ea4cd79aba85a9d722fa515977ccbefa19ac4945fb575053717f85898353 |