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.1.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.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic_registry-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 8056f9c54c25449f276c7c4e16a6d2e75b0017699dc3dc2b6aab5ef0bc220e2b
MD5 e7e12ddcee972465518a93d5d3a5f8cc
BLAKE2b-256 a2add9a9bc556cd470b6963d85eb9924ca5a95ed354163bb4bdadbd5652ca419

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dynamic_registry-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d23e13a9a4ba9937bb3ca6e0be7411539a5a6fe276228d15a8c9feefe7da820b
MD5 1e21126f15bcfceded946e48dacf5f9b
BLAKE2b-256 4bc0f6fad240784607b4451c4da6b78a8654951795dcba3d72a6bb130de1173a

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