0.88.0 Release Notes

This release launches st.download_button as well as other improvements and bug fixes

Posted in Release Notes,
0.88.0 Release Notes

Hey Streamlit Fam! ๐Ÿ‘‹

Say hello to a notable new feature in the 0.88.0 release: st.download_button. Now your viewers can download data right from your Streamlit apps!

In this post, we'll go into more detail about the new download button and other updates.

Want to jump right in? Here's a sample app and here are the docs.

โœจ Release Highlight

โฌ‡๏ธ Download Button

Before this release, you had to hack your way to the download functionality within Streamlit. None of the hacks were great. And they didn't play well with the Streamlit Cloud platform.

With st.download_button you can use the download functionality both locally and within our cloud platform.

Curious how it's built?

API Details

streamlit.download_button(label, data, file_name=None, mime=None, key=None, help=None, on_click=None, args=None, kwargs=None)

This will display a button for your viewers so they can download data locally to their machines.

Parameters

  • label (str) โ€“ A short label explaining to the user what this button is for.
  • data (str or bytes or file) โ€“ The contents of the file to be downloaded.
  • file_name (str) - An optional string to use as the name of the file to be downloaded, eg. 'my_file.csv'. If file_name is not specified, a name will be automatically generated.
  • mime (str or None) โ€“ The MIME type of the data. If data=str and MIME is unspecified, then MIME defaults to โ€œtext/plainโ€. If data=bytes and MIME is unspecified, then MIME defaults to โ€œapplication/octet-streamโ€.
  • key (str) โ€“ An optional string to use as the unique key for the widget. If you omit this, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.
  • help (str) โ€“ An optional tooltip that gets displayed when the button is hovered over.
  • on_click (callable) โ€“ An optional callback invoked when this button is clicked.
  • args (tuple) โ€“ An optional tuple of args to pass to the callback.
  • kwargs (dict) โ€“ An optional dict of kwargs to pass to the callback.

Returns

If the button was clicked on the last run of the app, it will be True. Otherwise, it will be False. Additionally, the return type is bool.

Example Usage

# Text files

text_contents = '''
Foo, Bar
123, 456
789, 000
'''

# Different ways to use the API

st.download_button('Download CSV', text_contents, 'text/csv')
st.download_button('Download CSV', text_contents)  # Defaults to 'text/plain'

with open('myfile.csv') as f:
	st.download_button('Download CSV', f)  # Defaults to 'text/plain'

# ---
# Binary files

binary_contents = b'whatever'

# Different ways to use the API

st.download_button('Download file', binary_contents)  # Defaults to 'application/octet-stream'

with open('myfile.zip', 'rb') as f:
	st.download_button('Download Zip', f, file_name='archive.zip')  # Defaults to 'application/octet-stream'

# You can also grab the return value of the button,
# just like with any other button.

if st.download_button(...):
	st.write('Thanks for downloading!')

๐Ÿงฉ Other notable updates

Below are some other notable updates on this release:

  • ๐Ÿ›‘ We made changes to improve the redacted exception experience on Streamlit Cloud. When client.showErrorDetails=true exceptions display the Error Type and Traceback, the actual error text will be redacted to prevent data leaks. [3713]
  • ๐Ÿ–ฅ๏ธ Macs are set to verify SSL in Python. If certificates aren't installed, a SSL: CERTIFICATE_VERIFY_FAILED error propagates. We removed HTTPS in order to solve this issue. [3744]
  • ๐Ÿ”‘ Integers can now also be used as keys in widget declarations. This helps community members who use integers for keys. This change ensures integer keys are converted to strings. [3697]

Click here to check out all updates.

๐Ÿ Wrapping up

Thanks for checking out the release notes for 0.88.0. You can always see the most recent updates on our change-log or via this tag on the forum.

Feel free to let us know in the comments below if you have any questions. We're looking forward to hearing what you think about the new download button!

Happy Streamliting. ๐ŸŽˆ

Share this post

Comments

Continue the conversation in our forums โ†’

Also in Release Notes...

View even more โ†’

We would like to use cookies to help us understand how users interact with this website.
This is used, for example, to find out which parts of this site should be further improved. More information can be found in our privacy policy.