Streamlit Downloader
A Streamlit component that triggers an automatic download of one or more files without requiring user interaction.
Installation
pip install streamlit-downloader
Usage
Use the downloader function to initiate a download. The component will automatically trigger the browser's download dialog when the page loads or when the component is rendered.
Downloading a Single File
import streamlit as st
from streamlit_downloader import downloader
# The `downloader` function returns True when the download is complete.
st.subheader("Download a single file")
data_to_download = b'Hello, this is the content of the file.'
filename = "my_text_file.txt"
content_type = "text/plain"
if st.button("Start Download"):
download_complete = downloader(
data=data_to_download,
filename=filename,
content_type=content_type
)
if download_complete:
st.success(f"File '{filename}' has been downloaded!")
Downloading Multiple Files
The downloader component can handle multiple files by being called multiple times.
import streamlit as st
from streamlit_downloader import downloader
st.subheader("Download multiple files")
# File 1 details
data_file1 = b"This is the first file."
filename_file1 = "file1.txt"
content_type_file1 = "text/plain"
# File 2 details
data_file2 = b"This is the second file."
filename_file2 = "file2.csv"
content_type_file2 = "text/csv"
if st.button("Download Both Files"):
# The component must be called for each file you want to download.
download_complete_1 = downloader(
data=data_file1,
filename=filename_file1,
content_type=content_type_file1,
)
download_complete_2 = downloader(
data=data_file2,
filename=filename_file2,
content_type=content_type_file2,
)
if download_complete_1 and download_complete_2:
st.success("All files have been downloaded!")
Parameters
The downloader function accepts the following parameters:
data: The raw data of the file to be downloaded. This can be a string, bytes, or a similar data type.filename: The name the downloaded file will have.content_type: The MIME type of the file (e.g.,text/csv,application/pdf).key: (Optional) A unique key for the component, required when you have multiple downloaders on the same page.
How It Works
The component leverages the browser's ability to trigger downloads using a hidden link element. When the Streamlit component is rendered, it uses JavaScript to create a Blob from the data, creates a temporary <a> element, sets its href to a URL created from the Blob, and simulates a click to initiate the download. The component is visually hidden to provide a seamless user experience.
Development
To run the example app and test changes:
- Navigate to the
streamlit_downloaderdirectory. - Run
streamlit run example.py.
Metadata
Release files for streamlit-downloader 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit_downloader-0.0.3.tar.gz | 125.9 kB | Without provenance | Details for streamlit_downloader-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_downloader-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for streamlit_downloader-0.0.3-py3-none-any.whl |
Total release size: 251.0 kB
Release files / streamlit_downloader-0.0.3.tar.gz
| Download URL | streamlit_downloader-0.0.3.tar.gz |
|---|---|
| Size | 125.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6794d28f9487f2db4f48ff829d60fd32c12ea2c349f558316480c991df57aa6
|
|
BLAKE2b-256 checksum How to use checksums |
57c5e0eaf3c1c831f4a54646763289db239651137947073435728970ea80b50a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / streamlit_downloader-0.0.3-py3-none-any.whl
| Download URL | streamlit_downloader-0.0.3-py3-none-any.whl |
|---|---|
| Size | 125.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4bb05e8be3f1afbd30f32d15c7e6e2017e4684d1ae6e67adfa843c6951a924cb
|
|
BLAKE2b-256 checksum How to use checksums |
2241f4ebeeddeeb84e6fb9d67394c59ab7093fd3568d4ec58b4b1e43c1c13e08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for streamlit-downloader 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.