Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 1016 Bytes

handlers.rst

File metadata and controls

28 lines (20 loc) · 1016 Bytes

Custom Handlers

When requesting a config-instance using :py~config_resolver.core.get_config it is possible to specify a custom file-handler using the handler keyword arg. For example:

from config_resolver import get_config
from config_resolver.handlers.json import JsonHandler

result = get_config('foo', 'bar', handler=JsonHandler)

Each handler has full control over the data type which is returned by :py~config_resolver.core.get_config. get_config always returns a named-tuple with two arguments:

  • config: This contains the object returned by the handler.
  • meta: This is a named-tuple which is generated by config_resolver and not modifyable by a handler. See the-meta-object.

A handler must be subclassed from :pyconfig_resolver.handler.base.Handler which allows us to provide good type-hinting.

See the existing handlers in :pyconfig_resolver.handler for some practical examples.