How to auto download csv files generated from a requests response

Hi community,

I am creating an app that uses requests to create a CSV file, the response will return a URL to download the file generated.

How can I automatically download the file into the User’s computer?

The idea is that they will upload to streamlit a file that contains the data of the items they want to generate a report to. A loop will take this info for each row in the file and generate the reports. For each loop iteration, the report has to be downloaded. since several reports will be generated, I want to have the report downloaded automatically avoiding the user to click a download button each iteration.

No idea what that is. Could post a sample code?

Is the app available publicly so we can maybe take a look at it? It’s hard to say without additional information, but I’m curious about the process. Can the files be appended or merged and still allow you to accomplish your goal?

I did come across this conversation below that sounds similar to this scenario and wanted to share in the event it will be helpful. Best of luck and have a good weekend.

1 Like

Hi @HectorHQ

Perhaps you can embed all widgets inside a st.form and upon clicking on the Submit button, all necessary processing are performed and culminating with a file download. As for having the file download occur without explicitly using the st.download_button, I think you can get some inspiration from the code snippet provided at this link: Automatic Download / Select and Download File with Single Button Click - #4 by snehankekre

Hope this helps!


Thank you all, I figured out by creating a list and saving the csv files on it, then iterating the list and saving a zip file. Finally I can use the st.download_button() to download the zip file that contains all the csv files.

Thanks for your support


Nice, glad that you’ve found a solution!

1 Like