Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
pgss
- Page-Specific SessionState for StreamlitThe pgss
package provides an easy way to manage session states in Streamlit applications on a per-page basis. By using PageSessionState
, you can ensure that variables are kept consistent across different pages, even if they have the same variable names. This package is perfect for managing page-specific data without interfering with other pages.
You can install pgss
using pip
:
pip install pgss
Once installed, you can use the PageSessionState class to manage session states for each page in your Streamlit app. Here's an example:
import streamlit as st
from pgss import PageSessionState # Import the PageSessionState class
# Create a PageSessionState object for the current page
pss = PageSessionState("page1.py")
# Initialize the session state variable if it does not exist
pss.set_if_not_exist({"count": 1, "text": ""})
# or set as usual
# if "count" not in pss:
# pss["count"] = 1
# Create a button to increment the counter
if st.button("Increment"):
pss["count"] += 1
# Display the current value of the count variable
st.write(f"Count: {pss['count']}")
# Use pss(name) to generate a unique key for the text input
if text := st.text_input("Input text", value=pss.text, key=pss("text_key")):
pss.text = text
st.write(f"pss.text_key: {pss.text_key}")
st.write(f"pss.text: {pss.text}")
Adding Keys to Session State You can add keys to the session state if they do not already exist using the following method:
Page-Specific SessionState:
By creating an instance of PageSessionState
using the current file (ex: page.py
), you ensure that the session state is unique to the page. This means that each page can maintain its own state, even if the same variable names are used on multiple pages.
Set Default Values:
The set_if_not_exist
method allows you to set default values for your session state variables if they haven't been initialized yet. This ensures that the state starts with predefined values.
Adding Keys to Session State:
You can add keys to the session state if they do not already exist using the following method:
if "count" not in pss:
pss["count"] = 1
Persistent Session State:
Session state variables are preserved as long as the user is on the same page, making it easy to store and update data across user interactions without losing it between reruns.
Generating Session State Names: The pss(name) method allows you to generate session state names dynamically. This is useful for creating unique keys for Streamlit widgets, ensuring that the session state is correctly managed.
You can use this approach in Streamlit applications with multiple pages. For instance, one page could manage a counter, while another page could manage a different state, but both could share the same variable name (count
) without interfering with each other.
This package is licensed under the MIT License. See the LICENSE file for more information.
pgss
, you can use the Python package manager pip
.FAQs
A package to manage session states per page in Streamlit
We found that pgss demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.