Skip to main content

st_tools

Tools for streamlit.

Persistent session_state across restarts.

Installation

pip install st-tools

Usage

import streamlit as st
from st_tools import SessionStateManager

valid_values = [
    "",
    "choice 1",
    "choice 2",
    "choice 3",
    "choice 4",
]

# 1. Create a Session State Manager
#    with a main key, valid values,
#    and default:
config = SessionStateManager(
    instance_id="unique-name",
    main_key=("selected_item", "", valid_values),
    keys=["pagesize"],
)


# 2. Use the main key, save it when changes:
selected_item = st.selectbox(
    "Pick item:",
    valid_values,
    key="selected_item",
    on_change=config.save
)

if selected_item:
    # 3. load the settings for the main-key-value:
    config.initialize({"pagesize": 20})

    # 4. Use the settings, save it when it changes
    pagesize = st.number_input(
        "Page size:", min_value=1, max_value=100, key="pagesize", on_change=config.save
    )
    print(pagesize)

    # 5. Save the settings
    config.save()

If you reload the page, it will keep the session_state keys.

Metadata

Release files for st-tools 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for st-tools 1.0.1
File Size Uploaded
st_tools-1.0.1.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for st-tools 1.0.1
File Interpreter ABI Platform
st_tools-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / st_tools-1.0.1.tar.gz

Download URL st_tools-1.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
295bb2402e0d39da7a9bc58bd04553bbcfd3bead5a48dc0e3b31654e78aac7be
BLAKE2b-256 checksum
How to use checksums
f04c892efd65507398a41b6ebc2ef924349f9a920d7e8512858cd2366681df42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / st_tools-1.0.1-py3-none-any.whl

Download URL st_tools-1.0.1-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06a4707bc48ba1b000af055877bebc48c8f40805c1a1cba5ace5bef2e8e76804
BLAKE2b-256 checksum
How to use checksums
76c7c4929fec6831f8b543b9e2993c3d220f137344f1e56e77510820fbc608da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page