title: Output CSV file for download without saving the csv in the server
body: <p>I am working on a api end-point that will be available for public use using Python's Fast API framework. It is already done and working but the way it works is I will create it, then save to the local directory of the server then read that file and return a csv file as a response to the user.</p>
  <p>My question is, how do I just return the csv file directly to the user without saving it in the server's directory. My code is like this right now</p>
  <pre><code>def export_client_invoice(client_id):
  
      invoice_doc = client_docs_db.view(&quot;client_invoice/by_client_id&quot;, key=int(client_id), include_docs=True)
  
      data = [&quot;value %d&quot; % i for i in range(1,4)]
  
      with open(&quot;./file.csv&quot;, 'w', newline='') as myfile:
      wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
      wr.writerow(data)
  
      file_like = open(&quot;./file.csv&quot;, mode=&quot;rb&quot;)
      response = StreamingResponse(file_like, media_type=&quot;text/csv&quot;)
      response.headers[&quot;Content-Disposition&quot;] = &quot;attachment; filename=export.csv&quot;
      
  return response
  </code></pre>