serial.write(b'\x03')
This may not work (or not work all the time) as it depends on the default encoding. If this is NOT utf-8 then pyserial will complain with the message :
TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
To avoid this you have to encode your string as utf-8, so to send an escape sequence (e.g. ESC [ z ) you can do:
ESC_CHAR = chr(27)
text=f"{ESC_CHAR}[z".encode("utf-8"
serial.write(text)
You can of course compress this to one line or a variable for convenience.