Treat binary data as a file object? December 5, 2023 by Tarik This is what StringIO (in Python 2) and io.BytesIO in (in Python 3) are for.