hashlib.sha1 gives you just the hash of the content hash of "keydata", which you specify as a parameter (note that you simply concatenate the two lines). The hmac call gives you the key hash of the string "data" using the string "key" as the key and sha1 as the hash function. The main difference between the two calls is that HMAC can only be played if you know the key so that you also know something about who created the hmac. SHA1 can only be used to detect that the content has not changed.
source share