๐ย ย Streamlit Notify
Submitted by Patrick Garrett
Summary
Queue and display Streamlit Status Elements like toasts, balloons, and snowflakes.
Docstring
Visit the PyPI page for more information.
Examples
example_status_elements
def example_status_elements():
from streamlit_notify import (
balloons_stn,
error_stn,
exception_stn,
info_stn,
notify,
snow_stn,
success_stn,
toast_stn,
warning_stn,
)
# Display various status elements as examples
# Call each status element exactly like in Streamlit
toast_stn("๐ Toast Notification Example")
balloons_stn()
snow_stn()
success_stn("โ
Success Notification Example")
info_stn("โน๏ธ Info Notification Example")
error_stn("โ Error Notification Example")
warning_stn("โ ๏ธ Warning Notification Example")
exception_stn("๐ Exception Notification Example")
notify() # Display all queued notifications
example_notify
def example_notify():
from streamlit_notify import notify
# show all queued notifications
notify()
# By default notify will remove notifications after displaying them.
# If you want to keep them in the queue, you can pass `remove=False`
notify(remove=False)
# Show queued toast notifications
notify(notification_type="toast")
# show queued success and toast notifications
notify(notification_type=["success", "toast"])
example_get_notification_queue
def example_get_notification_queue():
from streamlit_notify import get_notification_queue
# Get the toast notification queue
# With this you can access the queue directly, and manipulate it as needed
get_notification_queue(notification_type="toast")
"""
The notification queue supports standard list operations:
append(item) - Add notification to queue
extend(items) - Add multiple notifications
pop(index) - Remove and return notification at index
get(index) - Get notification without removing it
remove(item) - Remove specific notification
clear() - Remove all notifications
has_items() - Check if queue has notifications
is_empty() - Check if queue is empty
contains(item) - Check if notification exists in queue
get_all() - Get all notifications
size() - Get number of notifications
"""
example_get_notifications
def example_get_notifications():
from streamlit_notify import get_notifications
# Get all toast notifications
get_notifications(notification_type="toast")
# Get all success and toast notifications
get_notifications(notification_type=["toast", "success"])
# Get all notifications of all types
get_notifications()
"""
Notification:
Attributes:
base_widget: Callable[..., Any]
args: OrderedDict[str, Any]
priority: int = 0
data: Any = None
Properties:
name: str - Name of the notification type (e.g., 'toast')
Methods:
notify: Display the notification
"""
example_has_notifications
def example_has_notifications():
from streamlit_notify import has_notifications
# Check if there are any notifications in the queue
has_notifications()
# Check if there are any toast notifications
has_notifications("toast")
# Check if there are any success or toast notifications
has_notifications(["success", "toast"])
example_create_add_remove_notifications
def example_create_add_remove_notifications():
from streamlit_notify import (
add_notifications,
create_notification,
remove_notifications,
)
# Get the current toast notifications
notification = create_notification(
body="๐ Custom Toast Notification",
icon="โญ",
priority=4,
notification_type="toast",
)
# Add a new notification to the queue
# Automatically adds to the toast queue
add_notifications(notification)
# can also add multiple notifications at once
# Adds two of the same notification
add_notifications([notification, notification])
# Remove a specific notification from the queue
# Automatically removes from the toast queue (first match)
remove_notifications(notification)
# Can also remove multiple notifications at once
# Removes two of the same notification
remove_notifications([notification, notification])
example_clear_notifications
def example_clear_notifications():
from streamlit_notify import clear_notifications
# Clear all notifications from the queue
clear_notifications()
# Clear only toast notifications
clear_notifications(notification_type="toast")
# Clear success and toast notifications
clear_notifications(notification_type=["success", "toast"])