config_ninja.contrib
Backend implementations for third-party integrations.
Each backend is implemented as a subclass of config_ninja.backend.Backend in a module of this
package. The get_backend() function is used to retrieve the backend class given its module name.
Available Backends
config_ninja.contrib.appconfig
Integrate with the AWS AppConfig service.
config_ninja.contrib.local
Use a local file as the backend.
1"""Backend implementations for third-party integrations. 2 3Each backend is implemented as a subclass of `config_ninja.backend.Backend` in a module of this 4package. The `get_backend()` function is used to retrieve the backend class given its module name. 5 6## Available Backends 7 8### `config_ninja.contrib.appconfig` 9 10Integrate with the AWS AppConfig service. 11 12### `config_ninja.contrib.local` 13 14Use a local file as the backend. 15""" 16 17from __future__ import annotations 18 19import importlib 20 21from config_ninja.backend import Backend 22 23 24def get_backend(name: str) -> type[Backend]: 25 """Import the `config_ninja.backend.Backend` subclass for the given module name.""" 26 module = importlib.import_module(f'config_ninja.contrib.{name}') 27 for val in module.__dict__.values(): 28 try: 29 is_subclass = issubclass(val, Backend) 30 except TypeError: 31 continue 32 33 if is_subclass and val is not Backend: 34 return val # type: ignore[no-any-return] # is_subclass ensures the correct type 35 36 raise ValueError(f'No backend found for {name}') # pragma: no cover
25def get_backend(name: str) -> type[Backend]: 26 """Import the `config_ninja.backend.Backend` subclass for the given module name.""" 27 module = importlib.import_module(f'config_ninja.contrib.{name}') 28 for val in module.__dict__.values(): 29 try: 30 is_subclass = issubclass(val, Backend) 31 except TypeError: 32 continue 33 34 if is_subclass and val is not Backend: 35 return val # type: ignore[no-any-return] # is_subclass ensures the correct type 36 37 raise ValueError(f'No backend found for {name}') # pragma: no cover
Import the config_ninja.backend.Backend subclass for the given module name.