Skip to main content

Everything you need to implement maintainable and easy to use registry patterns in your project.

Project description

Fast Registry

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


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.2.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

registerer-0.2.2-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page