How to write an STL or PLY in binary to bytes

e.g. in Python, for both STLs and PLYs, I want to output a byte string rather than write directly to a file so I can use it in an API request.

E.g. something similar to vtk.vtkDataSetWriter()

writer = vtk.vtkSTLWriter()
writer.SetFileTypeToBinary()
writer.WriteToOutputStringOn()
writer.SetInputData(obj)
writer.GetBinaryOutputString()

HI @JeffreyWardman

vtkPLYWriter can write to output string:

https://vtk.org/doc/nightly/html/classvtkPLYWriter.html#a4df553b07d920ff69d5a6677509fc2e9

Thanks Mathieu. What about for STLs?

vtkSTLWriter does not support it sadly