In brief
io.StringIO handles text, while io.BytesIO handles bytes. They help when a library expects a file-like object but the data is already in memory.
Useful to know
io.StringIO handles text, while io.BytesIO handles bytes. They help when a library expects a file-like object but the data is already in memory. [1]
Choose the type required by the interface. Passing bytes to a text stream does not automatically decode them correctly. Make text-to-byte conversion explicit, and remember that retaining the complete stream has a memory cost.
Sources
For further detail and to check the information: