Skip to main content

streamlit-persistence

Allows for persistence of class/instance attributes when using Streamlit in Python

Getting started

Install using pip

pip install streamlit-persistence

or build from source

git clone https://github.com/yaphott/streamlit-persistence.git
cd streamlit-persistence
python3 -m pip install -U pip setuptools wheel
python3 -m pip install .

Using the module

  1. Use PersistentObject as the parent class
  2. Assign the Streamlit session_state to a class attribute named session_state
  3. Assign class/instance attributes as you would normally
    • Check the instantiated class for the instance attribute using hasattr (as you would check session_state for a given key)
import streamlit as st
from streamlit_persistence import PersistentObject


options = [None, "veggie", "pepperoni"]


class Test(PersistentObject):
    session_state = st.session_state

    def run(self):
        if not hasattr(self, "pizza"):
            self.pizza = None

        # Default to the index of previously selected
        selected = st.selectbox(
            "Select a pizza",
            options,
            index=options.index(self.pizza),
        )

        # Update instance attribute if user changes their selection
        if self.pizza != selected:
            self.pizza = selected
            st.experimental_rerun()

        st.success(f"You have selected the pizza: {self.pizza}")


def main():
    Test().run()


if __name__ == "__main__":
    main()

Metadata

Release files for streamlit-persistence 0.0.3

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

Source distribution (sdist)

Source distribution for streamlit-persistence 0.0.3
File Size Uploaded Provenance
streamlit-persistence-0.0.3.tar.gz 3.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-persistence 0.0.3
File Interpreter ABI Platform
streamlit_persistence-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / streamlit-persistence-0.0.3.tar.gz

Download URL streamlit-persistence-0.0.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e5ac8fe6567d2599b6a0e80c426a8c47899eec11d5f3ebfad30805de00602f84
BLAKE2b-256 checksum
How to use checksums
0d49bf234aca6373390ba42247b1fdbb9940c0467560eabbce76f6a3eb74c193
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.5

Release files / streamlit_persistence-0.0.3-py3-none-any.whl

Download URL streamlit_persistence-0.0.3-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f066efc894ab128f6c1f598e78feafdd270d0c0538b21a13ba0012589b020ca2
BLAKE2b-256 checksum
How to use checksums
e33443a9a080ec2d67ac0561b16da32d77890fce5040c80abd92d6bc228cdd36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.5

Security for streamlit-persistence 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

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