class_docstr: Contains session data for a single "user" of an active app
  (that is, a connected browser tab).
  
  Each AppSession has its own ScriptData, root DeltaGenerator, ScriptRunner,
  and widget state.
  
  An AppSession is attached to each thread involved in running its script.
class_docstr_tok: ["Contains","session","data","for","a","single","``","user","''","of","an","active","app","(","that","is",",","a","connected","browser","tab",")",".","Each","AppSession","has","its","own","ScriptData",",","root","DeltaGenerator",",","ScriptRunner",",","and","widget","state",".","An","AppSession","is","attached","to","each","thread","involved","in","running","its","script","."]
docstr: Initialize the AppSession.
  
  Parameters
  ----------
  script_data
      Object storing parameters related to running a script
  
  uploaded_file_manager
      Used to manage files uploaded by users via the Streamlit web client.
  
  script_cache
      The app's ScriptCache instance. Stores cached user scripts. ScriptRunner
      uses the ScriptCache to avoid having to reload user scripts from disk
      on each rerun.
  
  message_enqueued_callback
      After enqueuing a message, this callable notification will be invoked.
  
  local_sources_watcher
      The file watcher that lets the session know local files have changed.
  
  user_info
      A dict that contains information about the current user. For now,
      it only contains the user's email address.
  
      {
          "email": "example@example.com"
      }
  
      Information about the current user is optionally provided when a
      websocket connection is initialized via the "X-Streamlit-User" header.
  
  session_id_override
      The ID to assign to this session. Setting this can be useful when the
      service that a Streamlit Runtime is running in wants to tie the lifecycle of
      a Streamlit session to some other session-like object that it manages.
docstr_tok: ["Initialize","the","AppSession",".","Parameters","--","--","--","--","--","script_data","Object","storing","parameters","related","to","running","a","script","uploaded_file_manager","Used","to","manage","files","uploaded","by","users","via","the","Streamlit","web","client",".","script_cache","The","app","'s","ScriptCache","instance",".","Stores","cached","user","scripts",".","ScriptRunner","uses","the","ScriptCache","to","avoid","having","to","reload","user","scripts","from","disk","on","each","rerun",".","message_enqueued_callback","After","enqueuing","a","message",",","this","callable","notification","will","be","invoked",".","local_sources_watcher","The","file","watcher","that","lets","the","session","know","local","files","have","changed",".","user_info","A","dict","that","contains","information","about","the","current","user",".","For","now",",","it","only","contains","the","user","'s","email","address",".","{","``","email","''",":","``","example","@","example.com","''","}","Information","about","the","current","user","is","optionally","provided","when","a","websocket","connection","is","initialized","via","the","``","X-Streamlit-User","''","header",".","session_id_override","The","ID","to","assign","to","this","session",".","Setting","this","can","be","useful","when","the","service","that","a","Streamlit","Runtime","is","running","in","wants","to","tie","the","lifecycle","of","a","Streamlit","session","to","some","other","session-like","object","that","it","manages","."]
code: def __init__(
      self,
      script_data: ScriptData,
      uploaded_file_manager: UploadedFileManager,
      script_cache: ScriptCache,
      message_enqueued_callback: Optional[Callable[[], None]],
      local_sources_watcher: LocalSourcesWatcher,
      user_info: Dict[str, Optional[str]],
      session_id_override: Optional[str] = None,
  ) -> None:
      """Initialize the AppSession.
  
      Parameters
      ----------
      script_data
          Object storing parameters related to running a script
  
      uploaded_file_manager
          Used to manage files uploaded by users via the Streamlit web client.
  
      script_cache
          The app's ScriptCache instance. Stores cached user scripts. ScriptRunner
          uses the ScriptCache to avoid having to reload user scripts from disk
          on each rerun.
  
      message_enqueued_callback
          After enqueuing a message, this callable notification will be invoked.
  
      local_sources_watcher
          The file watcher that lets the session know local files have changed.
  
      user_info
          A dict that contains information about the current user. For now,
          it only contains the user's email address.
  
          {
              "email": "example@example.com"
          }
  
          Information about the current user is optionally provided when a
          websocket connection is initialized via the "X-Streamlit-User" header.
  
      session_id_override
          The ID to assign to this session. Setting this can be useful when the
          service that a Streamlit Runtime is running in wants to tie the lifecycle of
          a Streamlit session to some other session-like object that it manages.
      """
      # Each AppSession has a unique string ID.
      self.id = session_id_override or str(uuid.uuid4())
  
      self._event_loop = asyncio.get_running_loop()
      self._script_data = script_data
      self._uploaded_file_mgr = uploaded_file_manager
      self._script_cache = script_cache
  
      # The browser queue contains messages that haven't yet been
      # delivered to the browser. Periodically, the server flushes
      # this queue and delivers its contents to the browser.
      self._browser_queue = ForwardMsgQueue()
      self._message_enqueued_callback = message_enqueued_callback
  
      self._state = AppSessionState.APP_NOT_RUNNING
  
      # Need to remember the client state here because when a script reruns
      # due to the source code changing we need to pass in the previous client state.
      self._client_state = ClientState()
  
      self._local_sources_watcher: Optional[
          LocalSourcesWatcher
      ] = local_sources_watcher
      self._stop_config_listener: Optional[Callable[[], bool]] = None
      self._stop_pages_listener: Optional[Callable[[], bool]] = None
  
      self.register_file_watchers()
  
      self._run_on_save = config.get_option("server.runOnSave")
  
      self._scriptrunner: Optional[ScriptRunner] = None
  
      # This needs to be lazily imported to avoid a dependency cycle.
      from streamlit.runtime.state import SessionState
  
      self._session_state = SessionState()
      self._user_info = user_info
  
      self._debug_last_backmsg_id: Optional[str] = None
  
      LOGGER.debug("AppSession initialized (id=%s)", self.id)
  
imports: import asyncio
  import sys
  import uuid
  from enum import Enum
  from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union
  import streamlit.elements.exception
  from streamlit import config, runtime, source_util
  from streamlit.case_converters import to_snake_case
  from streamlit.logger import get_logger
  from streamlit.proto.BackMsg_pb2 import BackMsg
  from streamlit.proto.ClientState_pb2 import ClientState
  from streamlit.proto.Common_pb2 import FileURLs, FileURLsRequest
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
  from streamlit.proto.GitInfo_pb2 import GitInfo
  from streamlit.proto.NewSession_pb2 import Config, CustomThemeConfig, NewSession, UserInfo
  from streamlit.proto.PagesChanged_pb2 import PagesChanged
  from streamlit.runtime import caching, legacy_caching
  from streamlit.runtime.forward_msg_queue import ForwardMsgQueue
  from streamlit.runtime.metrics_util import Installation
  from streamlit.runtime.script_data import ScriptData
  from streamlit.runtime.scriptrunner import RerunData, ScriptRunner, ScriptRunnerEvent
  from streamlit.runtime.scriptrunner.script_cache import ScriptCache
  from streamlit.runtime.secrets import secrets_singleton
  from streamlit.runtime.uploaded_file_manager import UploadedFileManager
  from streamlit.version import STREAMLIT_VERSION_STRING
  from streamlit.watcher import LocalSourcesWatcher
label_desc: Use image node_id 1 to create a new AppSession object  with example: obj = AppSession(script_data, uploaded_file_manager, script_cache, message_enqueued_callback, local_sources_watcher, user_info, session_id_override)