def get_key(config, kwds, key, default=None, formatted='formatted',
    missing_ok=True):
    """
    Retreive the value of `key` from the mapping `config`.

    If `key` does not exist in `config`, return `default` instead.

    If `formatted` is a string, it determines the key name that
    determines whether `key` is a format string or not (default is
    yes). Otherwise, it is interpreted as a boolean directly.

    Parameters
    ----------
    config : dict
        The :ref:`plugins-data-configuration` dictionary to search.
    kwds : dict
        The :ref:`keywords` dictionary to use for replacements if
        `formatted` turns out to be truthy.
    key : str
        The name of the key in `config` containing the required value.
    default :
        The value to return if `key` is missing from `config`.
    formatted : str or bool
        Either the name of the key to get the formatted flag from (if a
        string), or the flag itself. In either case, ignored if the
        value is not a string.
    missing_ok : bool
        If truthy, missing values are replaced by `default`. Otherwise
        a :py:exc:`KeyError` is raised.

    Return
    ------
    The value in `config` associated with `key`, optionally formatted
    with `kwds`.
    """
    if missing_ok:
        value = config.get(key, default)
    else:
        value = config[key]
    if isinstance(value, str) and config.get(formatted, True):
        value = value.format(**kwds)
    return value
