Loading configs

"Under Construction" Sign

This section documents the functions used (usually on app start-up) to load the configuration from a file or from environment variables. It also describes functions that can help you add useful command-line arguments to your app related to config file paths, config file templates and documenting the app’s configuration options.

nx_config.fill_config(cfg: nx_config.config.Config, *, stream: Optional[TextIO] = None, fmt: Optional[nx_config.format.Format] = None, env_prefix: Optional[str] = None)
TODO: incl.: Document that env takes precedence over config files and that if an env var is present,

it must be a valid value (will not fallback to config file in case of invalid env var) and the corresponding value in the config file (if any) will not be used and therefore will not be validated. So an invalid entry in a config file might go unnoticed if it is overriden by an env var. Also: Document restrictions with env. vars and ini, incl.: - No strings/secrets with commas in collections - No strings/secrets with surrounding spaces in collections - env. vars only: Surrounding whitespace is kept for base types but not for single-element collections - ini only: Surrounding whitespace is trimmed for all types Also: Document behaviour when empty strings are given as input from INI or environment variables: | Typ | “” -> ?? | | — | — | | int, float, bool, UUID, datetime | ValueError | | str, SecretString, URL | “” | | Path | Path(“”) | | Optional[base_or_collection] | None | | tuple[base, …] | () | | frozenset[base] | frozenset() |

Parameters
  • cfg

  • stream

  • fmt

  • env_prefix

nx_config.fill_config_from_path(cfg: nx_config.config.Config, *, path: Optional[Union[str, os.PathLike]] = None, env_prefix: Optional[str] = None)

TODO: incl.: Refer to docs from fill_config

Parameters
  • cfg

  • path

  • env_prefix

nx_config.resolve_config_path(prefix: Optional[str] = None, *, cli_args: Optional[argparse.Namespace] = None) Optional[pathlib.Path]

TODO: incl.: Document precedence between env var and CLI arg.

Parameters
  • prefix

  • cli_args

Returns

nx_config.add_cli_options(parser: argparse.ArgumentParser, *, prefix: Optional[str] = None, config_t: Type[nx_config.config.Config])
TODO: incl.: Document each individual CLI option.

Also: When documenting config-path and generate-config, refer to the docs of fill_config (e.g. on the limitations of INI and env vars).

Parameters
  • parser

  • prefix

  • config_t

class nx_config.Format(value)

TODO