from hashlib import scrypt from os import urandom from base64 import urlsafe_b64encode salt = urandom(16) key = scrypt(b'password', salt=salt, n=16384, r=8, p=1, dklen=32) key_encoded = urlsafe_b64encode(key)