def replace_env_vars(conf):
    """Fill `conf` with environment variables, where appropriate.

    Any value of the from $VAR will be replaced with the environment variable
    VAR. If there are sub dictionaries, this function will recurse.

    This will preserve the original dictionary, and return a copy.
    """
    d = deepcopy(conf)
    for key, value in d.items():
        if type(value) == dict:
            d[key] = replace_env_vars(value)
        elif type(value) == str:
            if value[0] == '$':
                var_name = value[1:]
                d[key] = os.environ[var_name]

    return d
Fill `conf` with environment variables, where appropriate.

    Any value of the from $VAR will be replaced with the environment variable
    VAR. If there are sub dictionaries, this function will recurse.

    This will preserve the original dictionary, and return a copy.