How can I invoke streamlit from within python code?

Official supported & recommended way is via cli.

streamlit run your_app.py

But still, if you prefer to render the app from within python, in st 1.30 is

from streamlit import config as _config
from streamlit.web.bootstrap import run
_config.set_option("server.headless", True)
run('your_app.py', args=[], flag_options=[], is_hello=False)

But this could change from one release to another (as it’s not officially supported)