def METHOD_NAME(name: Union[str, h5py.File, h5py.Group], dsets: dict, attrs: dict) -> None:
    """Write the datasets and attributes to an HDF5 file or group.
    Parameters
    ----------
    name : str, h5py.File, h5py.Group
        The filename or an open h5py File or Group.
    dsets : dict
        Dictionary of data to be written as datasets.
    attrs : dict
        Dictionary of data to be written as attributes.
    """
    with open_h5(name, "w") as file:
        # write the datasets
        for key in dsets.keys():
            try:
                file.create_dataset(
                    key,
                    data=dsets[key],
                    compression="gzip",
                    compression_opts=9,
                )
            except TypeError:
                file.create_dataset(key, data=dsets[key])
        # write the attributes
        file.attrs.update(attrs)