Skip to main content

A wrapper around st.file_uploader that provides a library and gallery options.

Project description

Streamlit Uploads Library

Open in Streamlit

A simple uploads library and gallery for use in Streamlit projects. Check out the demo using the Streamlit Cloud button above. This package provides a simple wrapper around st.file_uploader with a save function included and also provides library and gallery views for use in Streamlit projects.

Installation

Installation is available via pip:

pip install streamlit-uploads-library

Usage

Using any of the provided views is easy, import streamlit_uploads_library and then instantiate the class with the required directory variable. Other options can be configured by passing in different variables when instantiating the class.

Library View

  • directory (str): A str() of the path to the folder containing the library images, for example, "assets".
  • file_extensions (tuple): A tuple() containing strings of the file extensions to include in the library, default is (".png", ".jpg", ".jpeg").
  • image_alignment (str): A str() with the CSS keyword that is used to align the images and details columns.
  • number_of_columns (int): An int() defining the number of required columns, default is 5.
  • show_details (bool): A bool() to show or hide the file and edit details, False hides them, default is True to show them.
  • uid (str): A str() containing a unique identifier allowing you to create multiple libraries on the same page containing the same images.
import streamlit as st
from streamlit_uploads_library.library import Library

st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
library = Library(directory="assets/landscape/")
library_columns = Library(directory="assets/portrait/", number_of_columns=4, uid="library-columns")
library_mixed = Library(directory="assets/mixed/", uid="mixed-library")

Gallery View

  • directory (str): A str() of the path to the folder containing the gallery images, for example, "assets".
  • file_extensions (tuple): A tuple() containing strings of the file extensions to include in the gallery, default is (".png", ".jpg", ".jpeg").
  • image_alignment (str): A str() with the CSS keyword that is used to align the images and details columns.
  • number_of_columns (int): An int() defining the number of required columns, default is 5.
  • show_details (bool): A bool() to show or hide the file and edit details, True shows them, default is False to hide them and create a gallery.
  • uid (str): A str() containing a unique identifier allowing you to create multiple galleries on the same page containing the same images.
import streamlit as st
from streamlit_uploads_library.gallery import Gallery

st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
default_gallery = Gallery(directory="assets/landscape/")
columns_gallery = Gallery(directory="assets/portrait/", number_of_columns=4, uid="gallery-columns")
mixed_gallery = Gallery(directory="assets/mixed/", uid="mixed-gallery")

Upload View

The file uploader comes with multiple options able to be configured including 2 different view types. It is not required to use this and you can easily replace it with your own, it is provided as a convenience so you don't need to create the code yourself or replicate it across multiple projects.

  • save_location (str): A str() of the path to the folder you wish to save images to, for example, "assets".
  • expander (bool): A bool() used to set the initial state of the expander, only used when using the "expander" widget_type.
  • file_extensions (list): A list() containing strings of the file extensions to include in the library, default is (".png", ".jpg", ".jpeg").
  • info_msg (str): A str() that is used to set an info message above the uploader, default is "Upload new files here.".
  • label (str): A str() used to set the label of the "expander" or the header in the "container" type widget, default is "Upload Files", can be set to None to not display it.
  • upload_label (str): A str() that is used to set the label of the file uploader widget, default is "Upload Files".
  • widget_type (str): A str() defining the type of widget to use to display the file uploader, options are "container" or "expander", default is "container".
import streamlit as st
from streamlit_uploads_library.uploads import UploadFiles

st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
default_uploader = UploadFiles(save_location="assets")
expander_uploader = UploadFiles(save_location="assets", widget_type="expander")

Caching

Streamlit Uploads Library makes use of the st.cache_resource decorator so the library and gallery on this page will load from the cache instead of reloading the images each time the app is run. You will probably want to clear your cache after uploading new files to your app, the file uploader view provided by this package takes care of that for you but if you use your own file uploader and save function then to clear the cache you can use the st.cache_resource.clear() function provided by Streamlit.

Example App (Demo)

To run the example application provided in the repository:

git clone https://github.com/hreikin/streamlit-uploads-library
cd streamlit-uploads-library/
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
streamlit run Home.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_uploads_library-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

streamlit_uploads_library-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_uploads_library-0.1.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_uploads_library-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5cc63c7bb55dad1415e9d8329d7f6002f0ba9a1a9e2842b33db46b0ea27eaf0
MD5 877883eea5d9529522053d2abb354625
BLAKE2b-256 3925f4abc96707b1cf4ead9279a40acd5e08636916ded06d222ef1d90c1fe156

See more details on using hashes here.

File details

Details for the file streamlit_uploads_library-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_uploads_library-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f12fabddb414f11968ef1b8cff1f5b949a363dd94128d592e1e0904981e1265
MD5 ffe3cb88cc942de3dd6d825b4bc9b665
BLAKE2b-256 31753d2a6a699b3a9caee35a14d458efcd9fbb8dd8217ed197aeeb3a93071a5f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page