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: Run a read-only SQL query.
  
  This method implements both query result caching (with caching behavior
  identical to that of using ``@st.cache_data``) as well as simple error handling/retries.
  
  .. note::
      Queries that are run without a specified ttl are cached indefinitely.
  
  Parameters
  ----------
  sql : str
      The read-only SQL query to execute.
  ttl : float, int, timedelta or None
      The maximum number of seconds to keep results in the cache, or
      None if cached results should not expire. The default is None.
  
  Returns
  -------
  pandas.DataFrame
      The result of running the query, formatted as a pandas DataFrame.
  
  Example
  -------
  >>> import streamlit as st
  >>>
  >>> conn = st.connection("snowpark")
  >>> df = conn.query("select * from pet_owners")
  >>> st.dataframe(df)
docstr_tok: ["Run","a","read-only","SQL","query",".","This","method","implements","both","query","result","caching","(","with","caching","behavior","identical","to","that","of","using","``","@","st.cache_data","``",")","as","well","as","simple","error","handling\/retries",".","..","note",":",":","Queries","that","are","run","without","a","specified","ttl","are","cached","indefinitely",".","Parameters","--","--","--","--","--","sql",":","str","The","read-only","SQL","query","to","execute",".","ttl",":","float",",","int",",","timedelta","or","None","The","maximum","number","of","seconds","to","keep","results","in","the","cache",",","or","None","if","cached","results","should","not","expire",".","The","default","is","None",".","Returns","--","--","--","-","pandas.DataFrame","The","result","of","running","the","query",",","formatted","as","a","pandas","DataFrame",".","Example","--","--","--","-",">",">",">","import","streamlit","as","st",">",">",">",">",">",">","conn","=","st.connection","(","``","snowpark","''",")",">",">",">","df","=","conn.query","(","``","select","*","from","pet_owners","''",")",">",">",">","st.dataframe","(","df",")"]
code: def query(
      self,
      sql: str,
      ttl: Optional[Union[float, int, timedelta]] = None,
  ) -> pd.DataFrame:
      """Run a read-only SQL query.
  
      This method implements both query result caching (with caching behavior
      identical to that of using ``@st.cache_data``) as well as simple error handling/retries.
  
      .. note::
          Queries that are run without a specified ttl are cached indefinitely.
  
      Parameters
      ----------
      sql : str
          The read-only SQL query to execute.
      ttl : float, int, timedelta or None
          The maximum number of seconds to keep results in the cache, or
          None if cached results should not expire. The default is None.
  
      Returns
      -------
      pandas.DataFrame
          The result of running the query, formatted as a pandas DataFrame.
  
      Example
      -------
      >>> import streamlit as st
      >>>
      >>> conn = st.connection("snowpark")
      >>> df = conn.query("select * from pet_owners")
      >>> st.dataframe(df)
      """
      from snowflake.snowpark.exceptions import (  # type:ignore[import]
          SnowparkServerException,
      )
      from tenacity import (
          retry,
          retry_if_exception_type,
          stop_after_attempt,
          wait_fixed,
      )
  
      @retry(
          after=lambda _: self.reset(),
          stop=stop_after_attempt(3),
          reraise=True,
          retry=retry_if_exception_type(SnowparkServerException),
          wait=wait_fixed(1),
      )
      def _query(sql: str) -> pd.DataFrame:
          with self._lock:
              return self._instance.sql(sql).to_pandas()
  
      # We modify our helper function's `__qualname__` here to work around default
      # `@st.cache_data` behavior. Otherwise, `.query()` being called with different
      # `ttl` values will reset the cache with each call, and the query caches won't
      # be scoped by connection.
      ttl_str = (
          str(  # Avoid adding extra `.` characters to `__qualname__`
              ttl
          ).replace(".", "_")
      )
      _query.__qualname__ = (
          f"{_query.__qualname__}_{self._connection_name}_{ttl_str}"
      )
      _query = cache_data(
          show_spinner="Running `snowpark.query(...)`.",
          ttl=ttl,
      )(_query)
  
      return _query(sql)
  
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 3 for calling the SnowparkConnection obj's underlying member method code with example usage: obj.query(sql, ttl) and returns: _query, self