def get_lib_and_tag_name(tag):
    """
    Takes a tag string and returns the tag library and tag name. For example,
    "app_tags.tag_name" is returned as "app_tags", "tag_name" and
    "app_tags.sub.tag_name" is returned as "app_tags.sub", "tag_name"
    """
    if '.' not in tag:
        raise ValueError('Tag string must be in the format "tag_lib.tag_name"')
    lib = tag.rpartition('.')[0]
    tag_name = tag.rpartition('.')[-1]
    return lib, tag_name