class_docstr: A connection to Snowflake using the Snowflake Python Connector. Initialize using
  ``st.connection("<name>", type="snowflake")``.
  
  SnowflakeConnection supports direct SQL querying using ``.query("...")``, access to
  the underlying Snowflake Python Connector object with ``.raw_connection``, and other
  convenience functions. See the methods below for more information.
  SnowflakeConnections should always be created using ``st.connection()``, **not**
  initialized directly.
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.
  show_spinner : boolean or string
      Enable the spinner. The default is to show a spinner when there is a
      "cache miss" and the cached resource is being created. If a string, the value
      of the show_spinner param will be used for the spinner text.
  params : list, tuple, dict or None
      List of parameters to pass to the execute method. This connector supports
      binding data to a SQL statement using qmark bindings. For more information
      and examples, see the `Snowflake Python Connector documentation
      <https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-example#using-qmark-or-numeric-binding>`_.
      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("snowflake")
  >>> 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",".","show_spinner",":","boolean","or","string","Enable","the","spinner",".","The","default","is","to","show","a","spinner","when","there","is","a","``","cache","miss","''","and","the","cached","resource","is","being","created",".","If","a","string",",","the","value","of","the","show_spinner","param","will","be","used","for","the","spinner","text",".","params",":","list",",","tuple",",","dict","or","None","List","of","parameters","to","pass","to","the","execute","method",".","This","connector","supports","binding","data","to","a","SQL","statement","using","qmark","bindings",".","For","more","information","and","examples",",","see","the","`","Snowflake","Python","Connector","documentation","<","https",":","\/\/docs.snowflake.com\/en\/developer-guide\/python-connector\/python-connector-example","#","using-qmark-or-numeric-binding",">","`","_",".","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","(","``","snowflake","''",")",">",">",">","df","=","conn.query","(","``","select","*","from","pet_owners","''",")",">",">",">","st.dataframe","(","df",")"]
code: def query(
      self,
      sql: str,
      *,  # keyword-only arguments:
      ttl: float | int | timedelta | None = None,
      show_spinner: bool | str = "Running `snowflake.query(...)`.",
      params=None,
      **kwargs,
  ) -> 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.
      show_spinner : boolean or string
          Enable the spinner. The default is to show a spinner when there is a
          "cache miss" and the cached resource is being created. If a string, the value
          of the show_spinner param will be used for the spinner text.
      params : list, tuple, dict or None
          List of parameters to pass to the execute method. This connector supports
          binding data to a SQL statement using qmark bindings. For more information
          and examples, see the `Snowflake Python Connector documentation
          <https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-example#using-qmark-or-numeric-binding>`_.
          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("snowflake")
      >>> df = conn.query("select * from pet_owners")
      >>> st.dataframe(df)
      """
      from snowflake.connector.errors import ProgrammingError  # type: ignore[import]
      from snowflake.connector.network import (  # type: ignore[import]
          BAD_REQUEST_GS_CODE,
          ID_TOKEN_EXPIRED_GS_CODE,
          MASTER_TOKEN_EXPIRED_GS_CODE,
          MASTER_TOKEN_INVALD_GS_CODE,
          MASTER_TOKEN_NOTFOUND_GS_CODE,
          SESSION_EXPIRED_GS_CODE,
      )
      from tenacity import (
          retry,
          retry_if_exception,
          stop_after_attempt,
          wait_fixed,
      )
  
      retryable_error_codes = {
          int(code)
          for code in (
              ID_TOKEN_EXPIRED_GS_CODE,
              SESSION_EXPIRED_GS_CODE,
              MASTER_TOKEN_NOTFOUND_GS_CODE,
              MASTER_TOKEN_EXPIRED_GS_CODE,
              MASTER_TOKEN_INVALD_GS_CODE,
              BAD_REQUEST_GS_CODE,
          )
      }
  
      @retry(
          after=lambda _: self.reset(),
          stop=stop_after_attempt(3),
          reraise=True,
          # We don't have to implement retries ourself for most error types as the
          # `snowflake-connector-python` library already implements retries for
          # retryable HTTP errors.
          retry=retry_if_exception(
              lambda e: isinstance(e, ProgrammingError)
              and hasattr(e, "errno")
              and e.errno in retryable_error_codes
          ),
          wait=wait_fixed(1),
      )
      def _query(sql: str) -> pd.DataFrame:
          cur = self._instance.cursor()
          cur.execute(sql, params=params, **kwargs)
          return cur.fetch_pandas_all()
  
      # 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=show_spinner,
          ttl=ttl,
      )(_query)
  
      return _query(sql)
  
file_path: streamlit/lib/streamlit/connections/snowflake_connection.py
imports: from __future__ import annotations
  from datetime import timedelta
  from typing import TYPE_CHECKING, cast
  import pandas
  from streamlit.connections import BaseConnection
  from streamlit.connections.util import running_in_sis
  from streamlit.errors import StreamlitAPIException
  from streamlit.runtime.caching import cache_data
label_desc: Use image node_id 2 for calling the SnowflakeConnection obj's underlying member method code with example usage: obj.query(sql) and returns: _query, cur