connect.external.snowflake
connect.external.snowflake
Snowflake SDK integration.
Snowflake SDK credentials implementations which support interacting with Posit OAuth integrations on Connect.
Notes
The APIs in this module are provided as a convenience and are subject to breaking changes.
Classes
Name | Description |
---|---|
PositAuthenticator | Authenticator for Snowflake SDK which supports Posit OAuth integrations on Connect. |
PositAuthenticator
connect.external.snowflake.PositAuthenticator(
self
=None
local_authenticator=None
client=None
user_session_token )
Authenticator for Snowflake SDK which supports Posit OAuth integrations on Connect.
Examples
import os
import pandas as pd
import snowflake.connector
import streamlit as st
from posit.connect.external.snowflake import PositAuthenticator
= os.getenv("SNOWFLAKE_ACCOUNT")
ACCOUNT = os.getenv("SNOWFLAKE_WAREHOUSE")
WAREHOUSE
# USER is only required when running the example locally with external browser auth
= os.getenv("SNOWFLAKE_USER")
USER
# https://docs.snowflake.com/en/user-guide/sample-data-using
= os.getenv("SNOWFLAKE_DATABASE", "snowflake_sample_data")
DATABASE = os.getenv("SNOWFLAKE_SCHEMA", "tpch_sf1")
SCHEMA = os.getenv("SNOWFLAKE_TABLE", "lineitem")
TABLE
= st.context.headers.get("Posit-Connect-User-Session-Token")
session_token = PositAuthenticator(
auth ="EXTERNALBROWSER", user_session_token=session_token
local_authenticator
)
= snowflake.connector.connect(
con =USER,
user=ACCOUNT,
account=WAREHOUSE,
warehouse=DATABASE,
database=SCHEMA,
schema=auth.authenticator,
authenticator=auth.token,
token
)
= con.cursor().execute("SELECT CURRENT_USER()").fetchone()
snowflake_user f"Hello, {snowflake_user[0]}!")
st.write(
with st.spinner("Loading data from Snowflake..."):
= pd.read_sql_query(f"SELECT * FROM {TABLE} LIMIT 10", con)
df
st.dataframe(df)
Attributes
Name | Description |
---|---|
authenticator | |
token |