def _string_to_base64(string):
 utf8_encoded = string.encode('utf-8')
 return base64.urlsafe_b64encode(utf8_encoded)

def _string_to_base64 ( string ) : utf8_encoded = string . encode ( 'utf-8' ) return base64 . urlsafe_b64encode ( utf8_encoded )
encodes string to utf-8 and then base64 .