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

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic_registry-0.1.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.3 Linux/6.14.0-27-generic

File hashes

Hashes for dynamic_registry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df44d20e771277b2dd677ca162613941fee8df4aacb30eb42fee910a3b4c8eff
MD5 0449930c4a44e25d0d122e7d24deccfe
BLAKE2b-256 784150fea2b33908d9980dd039a9711aae82b8321091e701c7a6951a0b89e19b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dynamic_registry-0.1.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.3 Linux/6.14.0-27-generic

File hashes

Hashes for dynamic_registry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56f5590ca1da1fee289aca073482c61915dda3ec90ff02aafbbadff033eb2d33
MD5 5f1ccaca9a8c5aeebf076c49c486ed97
BLAKE2b-256 3959bab0f8bceaed5c1deb18b5f381b1c3d9d1a6a52e1c2c0462d83ae5a136f5

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