import re


def tp_key_value(str_tag):
    """ Extract a key and a value from a string
        assumed to be a TaskPaper tag
    """
    rgx_split = re.compile(r'[\@\(\)\{\}]')
    str_key, str_value = '', ''

    # count the pieces
    lst_parts = rgx_split.split(str_tag)
    lng_parts = len(lst_parts)

    # and winnow the noise
    if lng_parts > 1:
        str_key = lst_parts[1]
        if lng_parts > 2:
            for str_value in lst_parts[2:]:
                if str_value != '':
                    break

    return (str_key, str_value)