from hashlib import sha256 from hmac import HMAC from base64 import b64encode # encode message with HMAC_SHA1 hm = HMAC('secretKey', 'message', sha256) # to hexdigit hmac_auth = hm.hexdigest() # or to base64 string hmac_auth = b64encode(hm.digest())