io.BytesIO()
io.BytesIO() is a Python function in the IO Module category. Creates an in-memory binary stream (like a file for bytes I/O). The syntax is io.BytesIO(initial_bytes=b""). Returns: BytesIO object. A typical example: from io import BytesIO
buf = BytesIO()
buf.write(b"binary data")
buf.seek(0)
content = buf.read(). A close sibling is io.StringIO(), which creates an in-memory text stream (like a file for string I/O). A close sibling is StringIO.getvalue(), which returns the entire contents of the StringIO buffer as a string. A close sibling is StringIO.seek(), which changes the stream position to the given offset. A close sibling is StringIO.truncate(), which truncates the stream to the specified size. More about this category: Stream handling — StringIO, BytesIO for in-memory I/O. Related IO Module entries: io.StringIO(), StringIO.getvalue(), StringIO.seek(), StringIO.truncate(), StringIO.close(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.