Metadata-Version: 2.1
Name: registerer
Version: 0.2.1
Summary: Everything you need to implement maintainable and easy to use registry patterns in your project.
Home-page: https://github.com/danialkeimasi/python-registerer
License: MIT
Author: Danial Keimasi
Author-email: danialkeimasi@gmail.com
Requires-Python: >=3.6,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Project-URL: Bug Tracker, https://github.com/danialkeimasi/python-registerer/issues
Description-Content-Type: text/markdown

# Fast Registry
[![](https://img.shields.io/pypi/v/python-registerer.svg)](https://pypi.python.org/pypi/python-registerer/)
[![](https://github.com/danialkeimasi/python-registerer/workflows/tests/badge.svg)](https://github.com/danialkeimasi/python-registerer/actions)
[![](https://img.shields.io/github/license/danialkeimasi/python-registerer.svg)](https://github.com/danialkeimasi/python-registerer/blob/master/LICENSE)

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

```sh
pip install fast-registry
```

# Register Classes
Register classes with the same interface, enforce the type check and enjoy the benefits of type hints:
```py
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):
```py
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
- [Class - Simple Type Checking](https://github.com/danialkeimasi/python-registerer/blob/main/examples/class.py)
- [Class - Custom Validator](https://github.com/danialkeimasi/python-registerer/blob/main/examples/class-with-custom-validator.py)
- [Function - Simple](https://github.com/danialkeimasi/python-registerer/blob/main/examples/function.py)
- [Function - With Type Annotation Validator](https://github.com/danialkeimasi/python-registerer/blob/main/examples/function-with-validator.py)

