# st_tools
Tools for streamlit.
Persistent session_state across restarts.
## Installation
```python
pip install st-tools
```
## Usage
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/dsblank/st_tools",
"name": "st-tools",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "streamlit",
"author": "st_tools Development Team",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/f0/4c/892efd65507398a41b6ebc2ef924349f9a920d7e8512858cd2366681df42/st_tools-1.0.1.tar.gz",
"platform": "Linux",
"description": "# st_tools\n\nTools for streamlit.\n\nPersistent session_state across restarts.\n\n## Installation\n\n```python\npip install st-tools\n```\n\n## Usage\n\n```python\nimport streamlit as st\nfrom st_tools import SessionStateManager\n\nvalid_values = [\n \"\",\n \"choice 1\",\n \"choice 2\",\n \"choice 3\",\n \"choice 4\",\n]\n\n# 1. Create a Session State Manager\n# with a main key, valid values,\n# and default:\nconfig = SessionStateManager(\n instance_id=\"unique-name\",\n main_key=(\"selected_item\", \"\", valid_values),\n keys=[\"pagesize\"],\n)\n\n\n# 2. Use the main key, save it when changes:\nselected_item = st.selectbox(\n \"Pick item:\",\n valid_values,\n key=\"selected_item\",\n on_change=config.save\n)\n\nif selected_item:\n # 3. load the settings for the main-key-value:\n config.initialize({\"pagesize\": 20})\n\n # 4. Use the settings, save it when it changes\n pagesize = st.number_input(\n \"Page size:\", min_value=1, max_value=100, key=\"pagesize\", on_change=config.save\n )\n print(pagesize)\n\n # 5. Save the settings\n config.save()\n```\n\nIf you reload the page, it will keep the session_state keys.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Tools for streamlit",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/dsblank/st_tools"
},
"split_keywords": [
"streamlit"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "76c7c4929fec6831f8b543b9e2993c3d220f137344f1e56e77510820fbc608da",
"md5": "cab76f07fa748c54c575dde0b76fe8b2",
"sha256": "06a4707bc48ba1b000af055877bebc48c8f40805c1a1cba5ace5bef2e8e76804"
},
"downloads": -1,
"filename": "st_tools-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cab76f07fa748c54c575dde0b76fe8b2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 4051,
"upload_time": "2024-12-12T19:09:24",
"upload_time_iso_8601": "2024-12-12T19:09:24.064934Z",
"url": "https://files.pythonhosted.org/packages/76/c7/c4929fec6831f8b543b9e2993c3d220f137344f1e56e77510820fbc608da/st_tools-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f04c892efd65507398a41b6ebc2ef924349f9a920d7e8512858cd2366681df42",
"md5": "573d502ec2d4ef7b9387e41927601b4e",
"sha256": "295bb2402e0d39da7a9bc58bd04553bbcfd3bead5a48dc0e3b31654e78aac7be"
},
"downloads": -1,
"filename": "st_tools-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "573d502ec2d4ef7b9387e41927601b4e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 3722,
"upload_time": "2024-12-12T19:09:25",
"upload_time_iso_8601": "2024-12-12T19:09:25.016741Z",
"url": "https://files.pythonhosted.org/packages/f0/4c/892efd65507398a41b6ebc2ef924349f9a920d7e8512858cd2366681df42/st_tools-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-12 19:09:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dsblank",
"github_project": "st_tools",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "st-tools"
}