import re


def snakify(name: str, *, sep: str = '_',
            _re_upper=re.compile(r'([A-Z])')) -> str:
    """Lowercase ``name`` adding ``sep`` before in-word-uppercase letters.

    >>> snakify('CamelCase')
    'camel_case'
    """
    return (name[:1] + _re_upper.sub(rf'{sep}\1', name[1:])).lower()