class_docstr: A connection to Snowpark using snowflake.snowpark.session.Session. Initialize using
  ``st.connection("<name>", type="snowpark")``.
  
  In addition to providing access to the Snowpark Session, SnowparkConnection supports
  direct SQL querying using ``query("...")`` and thread safe access using
  ``with conn.safe_session():``. See methods below for more information.
  SnowparkConnections should always be created using ``st.connection()``, **not**
  initialized directly.
  
  .. note::
      We don't expect this iteration of SnowparkConnection to be able to scale
      well in apps with many concurrent users due to the lock contention that will occur
      over the single underlying Session object under high load.
class_docstr_tok: ["A","connection","to","Snowpark","using","snowflake.snowpark.session.Session",".","Initialize","using","``","st.connection","(","``","<","name",">","''",",","type=","''","snowpark","''",")","``",".","In","addition","to","providing","access","to","the","Snowpark","Session",",","SnowparkConnection","supports","direct","SQL","querying","using","``","query","(","``","...","''",")","``","and","thread","safe","access","using","``","with","conn.safe_session","(",")",":","``",".","See","methods","below","for","more","information",".","SnowparkConnections","should","always","be","created","using","``","st.connection","(",")","``",",","*","*","not","*","*","initialized","directly",".","..","note",":",":","We","do","n't","expect","this","iteration","of","SnowparkConnection","to","be","able","to","scale","well","in","apps","with","many","concurrent","users","due","to","the","lock","contention","that","will","occur","over","the","single","underlying","Session","object","under","high","load","."]
docstr: Grab the underlying Snowpark session in a thread-safe manner.
  
  As operations on a Snowpark session are not thread safe, we need to take care
  when using a session in the context of a Streamlit app where each script run
  occurs in its own thread. Using the contextmanager pattern to do this ensures
  that access on this connection's underlying Session is done in a thread-safe
  manner.
  
  Information on how to use Snowpark sessions can be found in the `Snowpark documentation
  <https://docs.snowflake.com/en/developer-guide/snowpark/python/working-with-dataframes>`_.
  
  Example
  -------
  >>> import streamlit as st
  >>>
  >>> conn = st.connection("snowpark")
  >>> with conn.safe_session() as session:
  ...     df = session.table("mytable").limit(10).to_pandas()
  ...
  >>> st.dataframe(df)
docstr_tok: ["Grab","the","underlying","Snowpark","session","in","a","thread-safe","manner",".","As","operations","on","a","Snowpark","session","are","not","thread","safe",",","we","need","to","take","care","when","using","a","session","in","the","context","of","a","Streamlit","app","where","each","script","run","occurs","in","its","own","thread",".","Using","the","contextmanager","pattern","to","do","this","ensures","that","access","on","this","connection","'s","underlying","Session","is","done","in","a","thread-safe","manner",".","Information","on","how","to","use","Snowpark","sessions","can","be","found","in","the","`","Snowpark","documentation","<","https",":","\/\/docs.snowflake.com\/en\/developer-guide\/snowpark\/python\/working-with-dataframes",">","`","_",".","Example","--","--","--","-",">",">",">","import","streamlit","as","st",">",">",">",">",">",">","conn","=","st.connection","(","``","snowpark","''",")",">",">",">","with","conn.safe_session","(",")","as","session",":","...","df","=","session.table","(","``","mytable","''",")",".limit","(","10",")",".to_pandas","(",")","...",">",">",">","st.dataframe","(","df",")"]
code: def safe_session(self) -> Iterator["Session"]:
      """Grab the underlying Snowpark session in a thread-safe manner.
  
      As operations on a Snowpark session are not thread safe, we need to take care
      when using a session in the context of a Streamlit app where each script run
      occurs in its own thread. Using the contextmanager pattern to do this ensures
      that access on this connection's underlying Session is done in a thread-safe
      manner.
  
      Information on how to use Snowpark sessions can be found in the `Snowpark documentation
      <https://docs.snowflake.com/en/developer-guide/snowpark/python/working-with-dataframes>`_.
  
      Example
      -------
      >>> import streamlit as st
      >>>
      >>> conn = st.connection("snowpark")
      >>> with conn.safe_session() as session:
      ...     df = session.table("mytable").limit(10).to_pandas()
      ...
      >>> st.dataframe(df)
      """
      with self._lock:
          yield self.session
  
file_path: streamlit/lib/streamlit/connections/snowpark_connection.py
imports: import threading
  from collections import ChainMap
  from contextlib import contextmanager
  from datetime import timedelta
  from typing import TYPE_CHECKING, Iterator, Optional, Union, cast
  import pandas
  from streamlit.connections import BaseConnection
  from streamlit.connections.util import SNOWSQL_CONNECTION_FILE, load_from_snowsql_config_file, running_in_sis
  from streamlit.errors import StreamlitAPIException
  from streamlit.runtime.caching import cache_data
label_desc: Use image node_id 5 for calling the SnowparkConnection obj's underlying member method code with example usage: obj.safe_session() without return types