LTI Pro API X-Lti-Signature Generation in Python

Just wanted to share the solution I came up with for generating the X-Lti-Signature using Python:

import base64
import time
import hmac
from hashlib import sha1

LTI_KEY = 'from LTI Pro configuration page in marketplace'
LTI_SECRET = 'from LTI Pro configuration page in marketplace'

#get current unix timestamp in milliseconds
timestamp = str(int(time.time())) + '000'

#create base string using query parameters (LTI key & timestamp in milliseconds)
base_string = f'key={LTI_KEY}&timestamp={timestamp}'

#create HMAC object by passing base string and LTI secret to the HMAC-SHA1 hashing algorithm
hmac_object ='utf-8'), base_string.encode('utf-8'), sha1)

#get HMAC digest (returns bytes object)
hmac_object_digest = hmac_object.digest()

#signature equals converted HMAC digest to base64 URL safe string with trailing equal sign removed
signature = (base64.urlsafe_b64encode(hmac_object_digest)).decode('utf-8').rstrip('=')

#here's your X-Lti-Signature, valid for 60 minutes
print('Signature: ' + signature)

Hope this helps someone out!