_nonbmp = re.compile('[\\U00010000-\\U0010FFFF]')

def _surrogatepair(match):
    char = match.group()
assert ord(char) > 65535
encoded = char.encode('utf-16-le')
return chr(int.from_bytes(encoded[:2], 'little')) + chr(int.from_bytes(
    encoded[2:], 'little'))

def with_surrogates(text):
    return _nonbmp.sub(_surrogatepair, text)
Python: Find equivalent surrogate pair from non-BMP unicode char