Skip to main content

Registry with dynamic entries (can be enriched with data in runtime)

Project description

dynamic_registry

badge--license badge--python badge--pypi

badge--safety badge--codecov badge--gh-actions

Create registries with dynamic entries - which may be enriched with some data at runtime.

dynamic_registry provides an elegant and reusable way to create registries that dynamically track and manage entries. Useful for plugins, handlers, or any scenario requiring dynamic discovery and access to components.


Would like to support?

badge--buy-me-a-coffee badge--ko-fi


Installation

pip install dynamic-registry

Basic usage

from dynamic_registry import Registry, Entry


class ErrorsRegistry(metaclass=Registry):
    ERROR_404 = Entry(message='Not found!')
    ERROR_500 = Entry(message='Internal server error!')
    ERROR_501 = Entry(message='Not authorized!')


print(ErrorsRegistry.ERROR_500())
# Note, how dynamic enrichment works:
print(ErrorsRegistry.ERROR_501(user='Nigan', action='ACCESS_ALEXANDREA_SERVER', reason='User is in the blacklist!'))
print(ErrorsRegistry.ERROR_501(user='Rick', action='ACCESS_ALEXANDREA_SERVER', reason='Invalid username/password!'))
# You can even overwrite the key field and defaults defined during the class creation:
print(ErrorsRegistry.ERROR_500(message='Overwritten message!'))
print(ErrorsRegistry.ERROR_500(key='ERROR_500_OVERWRITTEN_KEY'))

for name, entry in ErrorsRegistry.entries.items():
    print(f'ENTRY: {name} ==> {entry}')

Options

Optionally, you can use custom entry key/name field (default is key) like this:

from dynamic_registry import Registry, Entry


class MyRegistry(metaclass=Registry, key_field='id'):
    ENTRY = Entry()


print(MyRegistry.ENTRY())

Or you can disable this behavior at all, by setting key_field to None:

from dynamic_registry import Registry, Entry


class MyRegistry(metaclass=Registry, key_field=None):
    ENTRY = Entry()


print(MyRegistry.ENTRY())

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

dynamic_registry-1.0.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

dynamic_registry-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic_registry-1.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for dynamic_registry-1.0.0.tar.gz
Algorithm Hash digest
SHA256 32c025d0ff6982ccb36ac6e0f761d1e47814c8b5515efed403289050736925a6
MD5 05341b5c4f09e917eba8d9d72b1fe6c7
BLAKE2b-256 59332de31a214fd2169ccbbe7f8085d32a874b2e3b73de65b62bc1f332e3ded8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dynamic_registry-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for dynamic_registry-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab9b7612bc5f419ca0506c8e6421355d2e76cec6a38e695fed64c7bedec5dfd6
MD5 d6b88f4cee99d5c8788ef1f85400d357
BLAKE2b-256 060fff0edc2b26a9fe526147453b7107621ef1764ca8b3904ce347524046bd13

See more details on using hashes here.

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