Updating text file

Hi, I have a text file that stores a variable for me but I can’t update the text file in streamlit.(this makes sense because it gets code from GitHub and you can’t update that) I was wondering if there was a way to do this

Hi @ShadowUTube, welcome to the forum!

You’re correct that storing the data in a text file is not ideal, at least when hosting on Streamlit Cloud, as that text file won’t exist permanently unless it’s saved in GitHub.

In general, it depends how long you need that variable (and any changes to it) to exist:

  • If it just needs to exist for one app run, then you don’t need to do anything special, just use a normal python variable
  • If it needs to exist for as long as a given user is using the app, you can use st.session_state Session State - Streamlit Docs
  • If the variable needs to exist permanently (including any changes to it), you’ll probably want to use a database of some sort to store the data. Streamlit doesn’t have a built-in database yet (though we’re looking into adding a build-in database in the near future to make problems like this easier), but there are a number of guides for connecting to external databases Connect to data sources - Streamlit Docs

Ok, thanks for all the help