semvec/pypi-packages huggingface dataset:
streamlit-persistence 0.0.3
Allows for persistence of class/instance attributes when using Streamlit in Python
Requires Python: >=3.9
Keywords: streamlit,persistence,attributes,data-science,developer-tools

# streamlit-persistence

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

## Getting started

### Install using pip

```bash
pip install streamlit-persistence
```

### or build from source

```bash
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)

```python
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()
```
toautosyspath 0.0.1
A python automatically adds the current project sys Path tool

# Auto sys path
## A python automatically adds the current project sys Path tool

### Use example:
example-project:  
&nbsp;&nbsp;&nbsp;&nbsp;- package1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- __init__.py  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- main.py  
&nbsp;&nbsp;&nbsp;&nbsp;- package2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- __init__.py  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- util.py  

at main.py
```python
import autosyspath

from package2.util import helloworld

helloworld()
```
<p>You can run anywhere main.py without error.</p>  
<p>example:</p>  
<p>&nbsp;&nbsp;&nbsp;&nbsp;> cd /example-project && python package1/main.py</p>  
<p>&nbsp;&nbsp;&nbsp;&nbsp;> cd / && python example-project/package1/main.py</p>  
<p>&nbsp;&nbsp;&nbsp;&nbsp;> cd /example-project/package1 && python main.py</p>  

<p>that's all ok.</p>