I have part of an API in Flask that currently returns a Numpy array in Json, I need to offer the option to return as a CSV rather than as Json.
The only way I have successfully done this is to save the Numpy array as a CSV using numpy.savetxt then serve that file. I have found I can not leave the file behind like this How can I generate file on the fly and delete it after download? however that still feels 'kludgy'
Is there a way to return a Numpy array as a CSV without going via the file?