import re
import keyword


def safe_transform(item: str) -> str:
    """
    Transform an arbitrary key into a safe key for dot notation

    Examples:
    >>> safe_transform("a,b")   # a_b
    >>> safe_transform("a_,_b") # a__b
    >>> safe_transform("in")    # _in

    Args:
        item: The item to be transformed

    Returns:
        The safely-transformed item
    """
    # // support bytes transform to keys in bytes?
    if isinstance(item, bytes):
        item = item.decode("utf-8")
    item = str(item)
    item = re.sub(r'[^A-Za-z0-9_]+', '.', item)
    item = re.sub(r'_?\.+|\.+_?', '_', item)
    if not item:
        return ''
    return ('_' + item
            if item[0] in '0123456789' or item in keyword.kwlist
            else item)