Streamlit Sortables
Streamlit Sortables is a component for Streamlit applications that allows users to create sortable lists. This component enhances the interactivity of your Streamlit apps by enabling users to sort lists of strings in the UI.
https://user-images.githubusercontent.com/329750/163662202-ce292fc4-2882-46ac-8c2c-ca4b9df675d2.mp4
Features
- Sortable Lists: Easily sort lists of strings or dictionaries.
- Multiple Containers: Support for sorting items across multiple containers.
- Custom Styling: Apply custom CSS styles to match your application's theme.
Installation
Install the package via pip:
pip install streamlit-sortables
Usage
Sorting a List of Strings
Use the sort_items method to sort a list of strings. The return value is the sorted list.
import streamlit as st
from streamlit_sortables import sort_items
original_items = ['A', 'B', 'C']
sorted_items = sort_items(original_items)
st.write(f'Original items: {original_items}')
st.write(f'Sorted items: {sorted_items}')
Sorting with Multiple Containers
You can pass a list of dictionaries with multi_containers=True to sort items across multiple containers.
import streamlit as st
from streamlit_sortables import sort_items
original_items = [
{'header': 'First Container', 'items': ['A', 'B', 'C']},
{'header': 'Second Container', 'items': ['D', 'E', 'F']}
]
sorted_items = sort_items(original_items, multi_containers=True)
st.write(f'Original items: {original_items}')
st.write(f'Sorted items: {sorted_items}')
Theme Customization
Here's a simple example of how to customize the theme by changing the background color and font size, and numbering the items. By default, styles are defined in SortableComponent.css:
import streamlit as st
from streamlit_sortables import sort_items
original_items = [
{'header': 'Container', 'items': ['Item 1', 'Item 2', 'Item 3']}
]
simple_style = """
.sortable-component {
background-color:rgb(0, 225, 255);
font-size: 16px;
counter-reset: item;
}
.sortable-item {
background-color: black;
color: white;
}
"""
sorted_items = sort_items(original_items, multi_containers=True, custom_style=simple_style)
st.write(f'Original items: {original_items}')
st.write(f'Sorted items: {sorted_items}')
This example changes the background color to a light blue, sets the font size to 16px, and numbers the items.
Advanced CSS Customization
This example demonstrates advanced CSS customization, including theme customization and item numbering. Apply custom CSS styles using the custom_style option.
import streamlit as st
from streamlit_sortables import sort_items
original_items = [
{'header': 'First Container', 'items': ['A', 'B', 'C']},
{'header': 'Second Container', 'items': ['D', 'E', 'F']}
]
custom_style = """
.sortable-component {
border: 3px solid #6495ED;
border-radius: 10px;
padding: 5px;
}
.sortable-container {
background-color: #F0F0F0;
counter-reset: item;
}
.sortable-container-header {
background-color: #FFBFDF;
padding-left: 1rem;
}
.sortable-container-body {
background-color: #F0F0F0;
}
.sortable-item, .sortable-item:hover {
background-color: #6495ED;
font-color: #FFFFFF;
font-weight: bold;
}
.sortable-item::before {
content: counter(item) ". ";
counter-increment: item;
}
"""
sorted_items = sort_items(original_items, multi_containers=True, custom_style=custom_style)
st.write(f'Original items: {original_items}')
st.write(f'Sorted items: {sorted_items}')
Contributing
Contributions are welcome! Please submit issues or pull requests for any bugs or feature requests.
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Metadata
Release files for streamlit-sortables 0.3.1
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_sortables-0.3.1.tar.gz | 564.1 kB | Without provenance | Details for streamlit_sortables-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_sortables-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for streamlit_sortables-0.3.1-py3-none-any.whl |
Total release size: 1.1 MB
Release files / streamlit_sortables-0.3.1.tar.gz
| Download URL | streamlit_sortables-0.3.1.tar.gz |
|---|---|
| Size | 564.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bed78f4407f2b9b1ddead8b6459d1af839aab427b7b5fe4c091e6870630acfe
|
|
BLAKE2b-256 checksum How to use checksums |
111000c3ae0f183d41bb3608157283a2c92e4f4db87cb21a73e96b3c2c2ca58f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.11.4 Darwin/23.6.0
|
Release files / streamlit_sortables-0.3.1-py3-none-any.whl
| Download URL | streamlit_sortables-0.3.1-py3-none-any.whl |
|---|---|
| Size | 570.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1847b2fa2041762b6442e21224bd8c0316c5412e4eb3a38fa748cf7ced834d49
|
|
BLAKE2b-256 checksum How to use checksums |
3db4edbef9fa8e49f5df2745a178c44b23553d8472c22fb23f44f6949d544410
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.11.4 Darwin/23.6.0
|
Security for streamlit-sortables 0.3.1
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.