Use session state in debugger

Has anyone found that they can’t use the debugger in their streamlit code anymore once they use the native state management? Now whenever I use the debugger, it’s as if it can’t store any data in the st.session_state object.

When I run the app, the code runs fine. However when I use my debugger in pycharm, I can’t get past the first line that accesses the st.session_state call because the “dictionary” is empty.

See this example:

st.session_state['foo'] = 'bar'
Traceback (most recent call last):
  File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/", line 381, in __getitem__
    return self._getitem(widget_id, key)
  File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/", line 424, in _getitem
    raise KeyError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/IPython/core/", line 3457, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-9404e5a9ae15>", line 1, in <module>
  File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/", line 666, in __getitem__
    return state[key]
  File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/", line 383, in __getitem__
    raise KeyError(_missing_key_error_message(key))
KeyError: 'st.session_state has no key "foo". Did you forget to initialize it? More info:'

How are we supposed to develop applications if we can’t use the debugger mode in our IDEs?

1 Like

anyone know the answer to this or have workarounds? surely I’m not the only one

I’m running into the same problem, have you found any workarounds?

Yes. Create a file called and then setup your application to run that.

from streamlit import bootstrap

def main():
    real_script = '', f' {real_script}', [], {})

if __name__ == "__main__":

Configure your IDE to run instead of, and then the bugger works because the actual streamlit server is kick started and paused in real time on your browser. st.session_state works then