end_len = len(h.hex_digest())
all_text = open('file_with_hash').read()
text, expected_hmac = all_text[:end_len], all_text[end_len:]
h = HMAC.new(secret_key)
h.update(text)
if h.hexdigest() != expected_hmac:
    raise 'Somebody messed with your file!'
Calculate and add hash to a file in python