import keyword


def validate_module_name(value, convert_lowercase=False, allow_keywords=False):
    """
    Validate a string to be used as python package or module name
    """
    if not isinstance(value, str):
        raise NameError(f'Module must be string: {value}')

    if not value.isidentifier():
        raise NameError(f'Name is not valid python identifier: {value}')

    if not allow_keywords and keyword.iskeyword(value):
        raise NameError(f'Name is a python keyword: {value}')

    lowercase = value.lower()
    if not convert_lowercase and lowercase != value:
        raise NameError(f'Name is not a lowercase string: {value}')

    if convert_lowercase:
        value = lowercase

    return value