docstr: The AppState class enables Frontend users to interact with their application state.
  
  When the state isn't defined, it would be pulled from the app REST API Server.
  If the state gets modified by the user, the new state would be sent to the API Server.
  
  Arguments:
      host: Rest API Server current host
      port: Rest API Server current port
      last_state: The state pulled on first access.
      state: The state modified by the user.
      my_affiliation: A tuple describing the affiliation this app state represents. When storing a state dict
          on this AppState, this affiliation will be used to reduce the scope of the given state.
      plugin: A plugin to handle authorization.
docstr_tok: ["The","AppState","class","enables","Frontend","users","to","interact","with","their","application","state",".","When","the","state","is","n't","defined",",","it","would","be","pulled","from","the","app","REST","API","Server",".","If","the","state","gets","modified","by","the","user",",","the","new","state","would","be","sent","to","the","API","Server",".","Arguments",":","host",":","Rest","API","Server","current","host","port",":","Rest","API","Server","current","port","last_state",":","The","state","pulled","on","first","access",".","state",":","The","state","modified","by","the","user",".","my_affiliation",":","A","tuple","describing","the","affiliation","this","app","state","represents",".","When","storing","a","state","dict","on","this","AppState",",","this","affiliation","will","be","used","to","reduce","the","scope","of","the","given","state",".","plugin",":","A","plugin","to","handle","authorization","."]
code: def __init__(
      self,
      host: Optional[str] = None,
      port: Optional[int] = None,
      last_state: Optional[Dict] = None,
      state: Optional[Dict] = None,
      my_affiliation: Tuple[str, ...] = None,
      plugin: Optional[BaseStatePlugin] = None,
  ) -> None:
      """The AppState class enables Frontend users to interact with their application state.
  
      When the state isn't defined, it would be pulled from the app REST API Server.
      If the state gets modified by the user, the new state would be sent to the API Server.
  
      Arguments:
          host: Rest API Server current host
          port: Rest API Server current port
          last_state: The state pulled on first access.
          state: The state modified by the user.
          my_affiliation: A tuple describing the affiliation this app state represents. When storing a state dict
              on this AppState, this affiliation will be used to reduce the scope of the given state.
          plugin: A plugin to handle authorization.
  
      """
      self._use_localhost = "LIGHTNING_APP_STATE_URL" not in os.environ
      self._host = host or (
          "http://127.0.0.1" if self._use_localhost else None
      )
      self._port = port or (
          APP_SERVER_PORT if self._use_localhost else None
      )
      self._last_state = last_state
      self._state = state
      self._session_id = "1234"
      self._my_affiliation = (
          my_affiliation
          if my_affiliation is not None
          else AppState._MY_AFFILIATION
      )
      self._authorized = None
      self._attach_plugin(plugin)
      self._session = self._configure_session()
  
imports: import enum
  import json
  import os
  from copy import deepcopy
  from time import sleep
  from typing import Any, Dict, List, Optional, Tuple, Union
  from deepdiff import DeepDiff
  from requests import Session
  from requests.exceptions import ConnectionError
  from lightning.app.core.constants import APP_SERVER_HOST, APP_SERVER_PORT
  from lightning.app.storage.drive import _maybe_create_drive
  from lightning.app.utilities.app_helpers import AppStatePlugin, BaseStatePlugin, Logger
  from lightning.app.utilities.network import LightningClient, _configure_session
label_desc: Use image node_id 1 to create a new AppState object  with example: obj = AppState(host, port, last_state, state, my_affiliation, plugin)