def compress(pub):
    '''
    Input must be hex string, and a valid uncompressed public key.
    Check if it's a valid key first, using the validatepubkey()
    function below, and then verify that the str len is 130.
    '''

    x = pub[2:66]
    y = pub[66:]
    if int(y,16) % 2:
        o = str('03') + str(x)
    else:
        o = str('02') + str(x)
    return o
Input must be hex string, and a valid uncompressed public key.
    Check if it's a valid key first, using the validatepubkey()
    function below, and then verify that the str len is 130.