Skip to content

Download Media

marimo.download

download(
    data: Union[str, bytes, BytesIO, BufferedReader],
    filename: Optional[str] = None,
    mimetype: Optional[str] = None,
    disabled: bool = False,
    *,
    label: str = "Download"
) -> Html

Show a download button for a url, bytes, or file-like object.

PARAMETER DESCRIPTION
data

The data to download. Can be a string (interpreted as a URL), bytes, or a file opened in binary mode.

TYPE: Union[str, bytes, BytesIO]

filename

The name of the file to download. If not provided, the name will be guessed from the data.

TYPE: str DEFAULT: None

mimetype

The mimetype of the file to download, for example, (e.g. "text/csv", "image/png"). If not provided, the mimetype will be guessed from the filename.

TYPE: str DEFAULT: None

disabled

Whether to disable the download button.

TYPE: bool DEFAULT: False

label

The label of the download button.

TYPE: str DEFAULT: 'Download'

RETURNS DESCRIPTION
Html

An Html object for a download button.

Example
download_txt = mo.download(
    data="Hello, world!".encode("utf-8"),
    filename="hello.txt",
    mimetype="text/plain",
)

download_image = mo.download(
    data=open("hello.png", "rb"),
)