import hmac from hashlib import sha1 from time import time NIBBLER_CUSTOMER_ID = 'xxx' PRIVATE_BUNCH_NAME = 'xxx' FILENAME = 'xxx' LINK_EXPIRE_SECONDS = 60 NIBBLER_ACCESS_KEY = 'xxx' expires = int(time() + LINK_EXPIRE_SECONDS) path = "/v1/AUTH_{customer_id}/{bunch}/{filename}".format( customer_id=NIBBLER_CUSTOMER_ID, bunch=PRIVATE_BUNCH_NAME, filename=FILENAME, ) hmac_body = "GET\n{expires}\n{path}".format( expires=expires, path=path, ) signature = hmac.new(NIBBLER_ACCESS_KEY, hmac_body, sha1).hexdigest() url = "https://almond.nibbler.io{path}?Signature={signature}&Expires={expires}".format( path=path, signature=signature, expires=expires, ) print url