Skip to main content

Tools for streamlit

Project description

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.

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

st_tools-1.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

st_tools-1.0.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file st_tools-1.0.1.tar.gz.

File metadata

  • Download URL: st_tools-1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for st_tools-1.0.1.tar.gz
Algorithm Hash digest
SHA256 295bb2402e0d39da7a9bc58bd04553bbcfd3bead5a48dc0e3b31654e78aac7be
MD5 573d502ec2d4ef7b9387e41927601b4e
BLAKE2b-256 f04c892efd65507398a41b6ebc2ef924349f9a920d7e8512858cd2366681df42

See more details on using hashes here.

File details

Details for the file st_tools-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: st_tools-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for st_tools-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 06a4707bc48ba1b000af055877bebc48c8f40805c1a1cba5ace5bef2e8e76804
MD5 cab76f07fa748c54c575dde0b76fe8b2
BLAKE2b-256 76c7c4929fec6831f8b543b9e2993c3d220f137344f1e56e77510820fbc608da

See more details on using hashes here.

Supported by

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