# Streamlit alternative st.session\_state

**URL:** <https://discuss.streamlit.io/t/streamlit-alternative-st-session-state/122304>\
**Category:** Using Streamlit\
**Tags:** discussion\
**Created:** [August 28, 2026, 10:27pm UTC](https://discuss.streamlit.io/t/streamlit-alternative-st-session-state/122304 "2026-08-28T22:27:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minh33](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/minh33/32/76963_2.png) [@Minh33](https://discuss.streamlit.io/u/Minh33)\
**Post date:** [August 28, 2026, 10:27pm UTC](https://discuss.streamlit.io/t/streamlit-alternative-st-session-state/122304/1 "2026-08-28T22:27:16Z")

</div>

Any alternate dictionary forms of storage I could store my oauth\_state or flow object that ain’t wiped by st.session\_state? For some reason when I get st.query\_params[“state”] and st.session\_state[“oauth\_state”] after these lines of code:

```auto
if "oauth_flow" not in st.session_state:

    flow = Flow.from_client_secrets_file(
        "credentials.json",
        scopes=SCOPES,
        redirect_uri=REDIRECT_URI,
    )

    authorization_url, state = flow.authorization_url(
        access_type="offline",
        prompt="consent",
    )

    st.session_state["oauth_flow"] = flow
    st.session_state["oauth_state"] = state
    st.session_state["authorization_url"] = authorization_url

Somehow the memory of st.session_state is not constant when a new tab is opened. I don't know what module or dictionary to use that is easy-to-implement and stuff. Thanks

```

---

<div class="post-metadata">

**Author:** ![AgentStreamy](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/agentstreamy/32/75102_2.png) [@AgentStreamy](https://discuss.streamlit.io/u/AgentStreamy)\
**Post date:** [August 28, 2026, 10:27pm UTC](https://discuss.streamlit.io/t/streamlit-alternative-st-session-state/122304/2 "2026-08-28T22:27:37Z")

</div>

Hey, thanks for your question! You’re absolutely right—`st.session_state` is only persistent for the current browser tab/session and gets wiped on refresh, new tabs, or after OAuth redirects. This is a common pain point for OAuth flows in Streamlit. There’s no built-in Streamlit dictionary or module that persists across sessions/tabs, as `st.session_state` is intentionally ephemeral and per-session.

For persistence across reloads or redirects, you’ll need to use an external store (like a database, file, or cookies). Some folks use browser cookies (with packages like `extra-streamlit-components`), or serialize state to disk (e.g., with pickle or JSON), or pass state via URL query parameters. See examples and discussion in [this forum thread](https://discuss.streamlit.io/t/session-state-not-persisting-after-redirect-msal-authentication-issue-in-streamlit/94721) and [this one](https://discuss.streamlit.io/t/some-code-for-cookie-based-session-management/54200). There’s no official Streamlit API for persistent, cross-session state.

Sources:

- [Session State not persisting after redirect (forum)](https://discuss.streamlit.io/t/session-state-not-persisting-after-redirect-msal-authentication-issue-in-streamlit/94721)
- [Cookie-based session management (forum)](https://discuss.streamlit.io/t/some-code-for-cookie-based-session-management/54200)
- [Streamlit Session State docs](https://docs.streamlit.io/develop/concepts/architecture/session-state#content-container)
