Skip to main content

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

Project description

Registerer

pypi ci codecov license

Sometimes you may want to use a string to identify a specific function or class. This is a common way of designing your code, but it can be tricky to do it without repeating yourself. Registerer is a tool that helps you to do this easily, and also makes sure that your code is explicit and type safe.

TLDR

Write this:

import registerer

command_handler_registry = registerer.Registerer()


@command_handler_registry.register()
def info(args):
    return "how can i help you?"


@command_handler_registry.register()
def play(args):
    return "let me play a song for you"


command = "info"
args = {}
assert command_handler_registry[command](args) == "how can i help you?"

Instead of this, which violates the Open-Closed Principle (OCP):

def info(args):
    return "how can i help you?"


def play(args):
    return "let me play a song for you"


def command_handler(command, args):
    if command == "info":
        return info(args)
    if command == "play":
        return play(args)


command = "play"
args = {}
assert command_handler(command, args) == "let me play a song for you"

Links

Installation

You can install the latest version of registerer from PyPI:

pip install registerer

Features

  • It's completely type-safe, thus you will get suggestions from your IDE.
  • Writing custom validations for registered items is provided without any inheritance.
  • generate choices for Django from registered items.
  • And so on...

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-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

registerer-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file registerer-1.0.0.tar.gz.

File metadata

  • Download URL: registerer-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for registerer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c810852e108a32412a05dbde26f6db183047bab41ee471cd3f121a669f75c500
MD5 6ed3fd430d8e61b3dde787a894fba1bf
BLAKE2b-256 59fe6b060afdb5af97be33e72b5ddbb84d7fa43302f0645ae89501d7cee5a985

See more details on using hashes here.

Provenance

The following attestation bundles were made for registerer-1.0.0.tar.gz:

Publisher: ci.yml on danialkeimasi/python-registerer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file registerer-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: registerer-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for registerer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53d93ea5c8753ad9806bd1fc846a5eb3bc33131bce5823cf6ea6a80e0d09abf4
MD5 3df08add61a9fbef95397f7d128f0183
BLAKE2b-256 51d0e124647adb09dd69294bb43d46b8fc449271b52216792ecdfebd3870bbd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for registerer-1.0.0-py3-none-any.whl:

Publisher: ci.yml on danialkeimasi/python-registerer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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