Running streamlit from script and keeping the context

Hello,

I’m currently setting up a script to run Streamlit by bypassing the command line tool like so:

sys.argv = ["streamlit", "run", my_script.__file__]
sys.exit(main())

However, it seems that by doing that, I don’t link any report context into my app. What will be the best way to create this context and assign it to the main running thread?

Thank you in advance.

Hi @antggt, welcome to the Streamlit community!

What is the high-level problem you’re trying to solve for here?

Thank you @randyzwitch,
I need to run Streamlit not from the command line tool because my executable is a self-contained environment.
Within my app, I want to access my session to create a state linked to each session.
It seems that generally, streamlit will create a fake browser in startup to have a context linked to it as well. I noticed that, by using this technique, there was no initial report context for my app, so I try to find out what is the best way to create that context and attach it the the main thread that is calling the app.

I’ll try and see if anyone on our engineering team has any intuition about this, it’s definitely a corner case to how we’ve expected people to try and deploy Streamlit

1 Like