from pathlib import Path
import hashlib


def get_md5(data, string=False) -> str:
    """Get MD5 hash from data or a file.

    Parameters
    ----------
    data: str, bytes or Path
        Input file or data.
    sting: bool, optional
        By default. stings are considered as filenames.
        Set `string` argument to `True` to process strings
        directly.

    Returns
    -------
    string
        Hex digest MD5 string.

    Raises
    ------
    FileNotFoundError
        If a filename is provided but does not exists.

    """
    if isinstance(data, str):
        return get_md5(data.encode('utf-8')) if string else get_md5(Path(data))

    if isinstance(data, Path):
        if not data.exists():
            raise FileNotFoundError(data)

        return get_md5(data.read_bytes())

    return hashlib.md5(data).hexdigest()