Streamlit and session variable - how do I create a session in one .py file and view it in another?

I am using streamlit and I call a function in a separate function file from a login script, the function.py queries SQL and loads a bunch of data in the st.session as follows:

st.session_state["company_id"] = company_id

Once the user has logged in , I want to reference that st.session_state[“company_id”] from the rest of my application in all the other .py files, I have tried to output st.session_state[“company_id”] and all I get is:
KeyError: 'st.session_state has no key “company_id”.Did you forget to initialize it?
I am running streamlit on local machine - python v3.11.5 / streamlit v1.28.0

There must be something else going on that is altering the session state, or the code that is setting company_id isn’t actually running. Here is an example of a main streamlit page, a sample1.py script that is imported, and a second page called pages/another_page.py

When I do streamlit run app37.py, I see 42, and when I switch to “another page”, I also see 42.

Can you show a simplified example of your code which shows you setting the session state variable and then not seeing it when you try to use it from another file?