Csv or other files saved in session by stremlit app hosted on streamlit cloud are session based or global?

About app: I am already running a streamlit app on streamlit clould which highly uses session-state as to allow flow of information between pages. It is meant for multiple users at same time and to prevent cross talks have not used any data caching.

Doubt: I am also running a subprocess python script which will need information/results to be fetched from streamlit data processing pages script either in form of csv or yaml or json or other files to transfer information to this subprocess script.

So if multiple user’s files are getting saved in csv format at the same time then is it getting saved only in their own session ?
If in session then csv file fetched by them running in that session will also fetch the session based csv file only … is this correct and expected or is it Global and not the session based ?

I want to keep the transfer of files/information within the session from streamlit generated data analytics to subrocess running python script in that session.

I am New to subprocess and session sort of development so not sure how it will be handled within streamlit.

To add more to above query.

  1. I am taking user file as input through streamlit interface.
  2. Performing Data processing and analytics over it.
  3. Will enable user to download html/pdf report on download button (that will run a subprocess).
  4. Subprocess contains Quarto/qmd file (similar to markdown jupyter notebook) for rendering html/pdf report.
  5. This Quarto has to read data results from streamlit scripts data processing and create html notebook.
  6. I am able to do the later process but not sure about how to transfer data from streamlit scripts to Quarto doc.

Session State is tied to a particular session, yes. If you save something in Session State, it’s only available to that one user in that one session where it was saved. If the same user opens another tab, they start a new session and don’t have access to the data in Session State from their original tab.

If you write to a file on disk, it will be available to all sessions.
If you cache data, it will be available to all sessions.

Thanks for the reply.

I am planning to write the file like csv but I want to link that file to that particular session only so that one user doesn’t overwrite another user’s file with same name and cause cross talk.

Workaround I can think of is to get some session id info (unique ids) and by using that as part of name I can save/write the file on disk so that when Quarto qmd file runs in same streamlit session then it can read the file saved with same session name.

Is it possible to get session info or session id ?

You can generate your own.

import uuid

import streamlit as st


def get_session_id():
    if "_session_id_" not in st.session_state:
        st.session_state["_session_id_"] = uuid.uuid4()
    return st.session_state["_session_id_"]

Thanks alot for sharing this. This will solve all my problems in this respect !!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.