{"id":15288062,"url":"https://github.com/yaphott/streamlit-persistence","last_synced_at":"2025-04-13T06:33:57.780Z","repository":{"id":62591630,"uuid":"477232017","full_name":"yaphott/streamlit-persistence","owner":"yaphott","description":"Allows for persistence of class attributes when using Streamlit in Python.","archived":false,"fork":false,"pushed_at":"2022-12-05T02:54:14.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T23:04:38.943Z","etag":null,"topics":["attributes","data-science","developer-tools","persistence","python","streamlit"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/streamlit-persistence","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yaphott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-03T03:53:15.000Z","updated_at":"2024-05-11T06:26:01.000Z","dependencies_parsed_at":"2023-01-23T07:15:55.660Z","dependency_job_id":null,"html_url":"https://github.com/yaphott/streamlit-persistence","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaphott%2Fstreamlit-persistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaphott%2Fstreamlit-persistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaphott%2Fstreamlit-persistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaphott%2Fstreamlit-persistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yaphott","download_url":"https://codeload.github.com/yaphott/streamlit-persistence/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674686,"owners_count":21143760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attributes","data-science","developer-tools","persistence","python","streamlit"],"created_at":"2024-09-30T15:44:00.586Z","updated_at":"2025-04-13T06:33:57.731Z","avatar_url":"https://github.com/yaphott.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# streamlit-persistence\n\nAllows for persistence of class/instance attributes when using Streamlit in Python\n\n## Getting started\n\n### Install using pip\n\n```bash\npip install streamlit-persistence\n```\n\n### or build from source\n\n```bash\ngit clone https://github.com/yaphott/streamlit-persistence.git\ncd streamlit-persistence\npython3 -m pip install -U pip setuptools wheel\npython3 -m pip install .\n```\n\n### Using the module\n\n1. Use `PersistentObject` as the parent class\n2. Assign the Streamlit `session_state` to a class attribute named `session_state`\n3. Assign class/instance attributes as you would normally\n   - Check the instantiated class for the instance attribute using `hasattr` (as you would check `session_state` for a given key)\n\n```python\nimport streamlit as st\nfrom streamlit_persistence import PersistentObject\n\n\noptions = [None, \"veggie\", \"pepperoni\"]\n\n\nclass Test(PersistentObject):\n    session_state = st.session_state\n\n    def run(self):\n        if not hasattr(self, \"pizza\"):\n            self.pizza = None\n\n        # Default to the index of previously selected\n        selected = st.selectbox(\n            \"Select a pizza\",\n            options,\n            index=options.index(self.pizza),\n        )\n\n        # Update instance attribute if user changes their selection\n        if self.pizza != selected:\n            self.pizza = selected\n            st.experimental_rerun()\n\n        st.success(f\"You have selected the pizza: {self.pizza}\")\n\n\ndef main():\n    Test().run()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaphott%2Fstreamlit-persistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaphott%2Fstreamlit-persistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaphott%2Fstreamlit-persistence/lists"}