def write(settings_path, settings_data, merge=True):
    """Write data to a settings file.

    :param settings_path: the filepath
    :param settings_data: a dictionary with data
    :param merge: boolean if existing file should be merged with new data
    """
    settings_path = Path(settings_path)
    if settings_path.exists() and merge:  # pragma: no cover
        try:  # tomllib first
            with open(str(settings_path), "rb") as open_file:
                object_merge(tomllib.load(open_file), settings_data)
        except UnicodeDecodeError:  # pragma: no cover
            # uiri/toml fallback (TBR on 4.0.0)
            with open(
                str(settings_path),
                encoding=default_settings.ENCODING_FOR_DYNACONF,
            ) as open_file:
                object_merge(toml.load(open_file), settings_data)

    try:  # tomllib first
        with open(str(settings_path), "wb") as open_file:
            tomllib.dump(encode_nulls(settings_data), open_file)
    except UnicodeEncodeError:  # pragma: no cover
        # uiri/toml fallback (TBR on 4.0.0)
        with open(
            str(settings_path),
            "w",
            encoding=default_settings.ENCODING_FOR_DYNACONF,
        ) as open_file:
            toml.dump(encode_nulls(settings_data), open_file)

        warnings.warn(
            "TOML files should have only UTF-8 encoded characters. "
            "starting on 4.0.0 dynaconf will stop allowing invalid chars.",
        )
Write data to a settings file.

    :param settings_path: the filepath
    :param settings_data: a dictionary with data
    :param merge: boolean if existing file should be merged with new data
    
dynaconf/loaders/toml_loader.py