How can I invoke streamlit from within python code?

Hello Folks,

What is the best means to invoke streamlit from within python code ?
I dont want to go via the CLI route of streamlit run <script-name.py>


This link has some reference, but again to invoke as mentioned in link, python click context is needed.

Thankyou
Jacob

Looks like this is a way:

import os
import streamlit.bootstrap
from streamlit import config as _config

dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'app.py')

_config.set_option("server.headless", True)
args = []

#streamlit.cli.main_run(filename, args)
streamlit.bootstrap.run(filename,'',args)
1 Like