DocumentationsearchSearchrocket_launchGet startedInstallationaddFundamentalsaddFirst stepsaddcodeDevelopConceptsaddAPI referenceremovePAGE ELEMENTSWrite and magicaddText elementsaddData elementsaddChart elementsaddInput widgetsaddMedia elementsaddLayouts and containersaddChat elementsaddStatus elementsaddThird-party componentsopen_in_newAPPLICATION LOGICNavigation and pagesaddExecution flowaddCaching and stateaddConnections and secretsremoveSECRETSst.secretssecrets.tomlCONNECTIONSst.connectionSnowflakeConnectionSQLConnectionBaseConnectionSnowparkConnectiondeleteCustom componentsaddUtilitiesaddConfigurationaddTOOLSApp testingaddCommand lineaddTutorialsaddQuick referenceaddweb_assetDeployConceptsaddStreamlit Community CloudaddStreamlit in Snowflakeopen_in_newOther platformsaddschoolKnowledge baseFAQInstalling dependenciesDeployment issuesHome/Develop/API reference/Connections and secrets/SnowparkConnectionpriority_highImportantThis is an experimental feature. Experimental features and their APIs may change or be removed at any time. To learn more, click here.
starTipThis page only contains the st.connections.SnowparkConnection class. For a deeper dive into creating and managing data connections within Streamlit apps, read Connecting to data.
st.connections.SnowparkConnectionStreamlit VersionVersion 1.34.0Version 1.33.0Version 1.32.0Version 1.31.0Version 1.30.0Version 1.29.0Version 1.28.0Version 1.27.0Version 1.26.0Version 1.25.0Version 1.24.0Version 1.23.0Version 1.22.0Version 1.21.0Version 1.20.0Version 1.19.0Version 1.18.0Version 1.17.0Version 1.16.0Version 1.15.0Version 1.14.0Version 1.13.0Streamlit in SnowflakedeleteDeprecation noticest.connections.SnowParkConnection was deprecated in version 1.28.0. Use st.connections.SnowflakeConnection instead.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 description[source] st.connections.SnowparkConnection(connection_name, **kwargs) Methods

query(sql, ttl=None)
 
Run a read-only SQL query.


reset()
 
Reset this connection so that it gets reinitialized the next time it's used.


safe_session()
 
Grab the underlying Snowpark session in a thread-safe manner.
Attributes

session
 
Access the underlying Snowpark session.

SnowparkConnection.queryStreamlit VersionVersion 1.34.0Version 1.33.0Version 1.32.0Version 1.31.0Version 1.30.0Version 1.29.0Version 1.28.0Version 1.27.0Version 1.26.0Version 1.25.0Version 1.24.0Version 1.23.0Version 1.22.0Version 1.21.0Version 1.20.0Version 1.19.0Version 1.18.0Version 1.17.0Version 1.16.0Version 1.15.0Version 1.14.0Version 1.13.0Streamlit in SnowflakeRun 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.

Function signature[source] SnowparkConnection.query(sql, ttl=None) 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)



SnowparkConnection.resetStreamlit VersionVersion 1.34.0Version 1.33.0Version 1.32.0Version 1.31.0Version 1.30.0Version 1.29.0Version 1.28.0Version 1.27.0Version 1.26.0Version 1.25.0Version 1.24.0Version 1.23.0Version 1.22.0Version 1.21.0Version 1.20.0Version 1.19.0Version 1.18.0Version 1.17.0Version 1.16.0Version 1.15.0Version 1.14.0Version 1.13.0Streamlit in SnowflakeReset this connection so that it gets reinitialized the next time it's used.
This method can be useful when a connection has become stale, an auth token has
expired, or in similar scenarios where a broken connection might be fixed by
reinitializing it. Note that some connection methods may already use reset()
in their error handling code.
Function signature[source] SnowparkConnection.reset() Example

import streamlit as st

conn = st.connection("my_conn")

# Reset the connection before using it if it isn't healthy
# Note: is_healthy() isn't a real method and is just shown for example here.
if not conn.is_healthy():
    conn.reset()

# Do stuff with conn...



SnowparkConnection.safe_sessionStreamlit VersionVersion 1.34.0Version 1.33.0Version 1.32.0Version 1.31.0Version 1.30.0Version 1.29.0Version 1.28.0Version 1.27.0Version 1.26.0Version 1.25.0Version 1.24.0Version 1.23.0Version 1.22.0Version 1.21.0Version 1.20.0Version 1.19.0Version 1.18.0Version 1.17.0Version 1.16.0Version 1.15.0Version 1.14.0Version 1.13.0Streamlit in SnowflakeGrab 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.
Function signature[source] SnowparkConnection.safe_session() 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)



SnowparkConnection.sessionStreamlit VersionVersion 1.34.0Version 1.33.0Version 1.32.0Version 1.31.0Version 1.30.0Version 1.29.0Version 1.28.0Version 1.27.0Version 1.26.0Version 1.25.0Version 1.24.0Version 1.23.0Version 1.22.0Version 1.21.0Version 1.20.0Version 1.19.0Version 1.18.0Version 1.17.0Version 1.16.0Version 1.15.0Version 1.14.0Version 1.13.0Streamlit in SnowflakeAccess the underlying Snowpark session.

Note
Snowpark sessions are not thread safe. Users of this method are
responsible for ensuring that access to the session returned by this method is
done in a thread-safe manner. For most users, we recommend using the thread-safe
safe_session() method and a with block.

Information on how to use Snowpark sessions can be found in the Snowpark documentation.
Function signature[source] SnowparkConnection.session Example

import streamlit as st

session = st.connection("snowpark").session
df = session.table("mytable").limit(10).to_pandas()
st.dataframe(df)


Previous: st.experimental_connectionNext: ExperimentalBaseConnectionforumStill have questions?Our forums are full of helpful information and Streamlit experts.HomeContact UsCommunity© 2024 Snowflake Inc.Cookie policy