The third option (while waiting for the next release) is to install streamlit-nightly
and modify your _get_session()
method to the following:
from streamlit.runtime.scriptrunner import get_script_run_ctx
import streamlit as st
from streamlit import runtime
def _get_session():
ctx = get_script_run_ctx()
if ctx is None:
return None
session_client = runtime.get_instance().get_client(ctx.session_id)
if session_client is None:
return None
return session_client._session_id
st.write(_get_session())