Skip to content

Commit fb80f1d

Browse files
committed
Copy in existing example app and add title to each file
1 parent 3f42531 commit fb80f1d

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

src/posit/connect/external/databricks.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
"""
2+
Databricks SDK credentials implementations which support interacting with Posit OAuth integrations on Connect.
3+
4+
NOTE: These APIs are provided as a convenience and are subject to breaking changes:
5+
https://github.com/databricks/databricks-sdk-py#interface-stability
6+
"""
7+
18
import abc
29
from typing import Callable, Dict, Optional
310

411
from ..client import Client
512
from ..oauth import Credentials
613
from .external import is_local
714

8-
"""
9-
NOTE: These APIs are provided as a convenience and are subject to breaking changes:
10-
https://github.com/databricks/databricks-sdk-py#interface-stability
11-
"""
12-
1315
POSIT_OAUTH_INTEGRATION_AUTH_TYPE = "posit-oauth-integration"
1416

1517
# The Databricks SDK CredentialsProvider == Databricks SQL HeaderFactory

src/posit/connect/external/snowflake.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
1+
"""Snowflake SDK credentials implementations which support interacting with Posit OAuth integrations on Connect.
2+
3+
NOTE: The APIs in this module are provided as a convenience and are subject to breaking changes.
4+
"""
5+
16
from typing import Optional
27

38
from ..client import Client
49
from .external import is_local
510

6-
"""
7-
NOTE: The APIs in this module are provided as a convenience and are subject to breaking changes.
8-
"""
9-
1011

1112
class PositAuthenticator:
13+
"""
14+
Authenticator for Snowflake SDK which supports Posit OAuth integrations on Connect.
15+
16+
Examples
17+
--------
18+
```python
19+
import os
20+
21+
import pandas as pd
22+
import snowflake.connector
23+
import streamlit as st
24+
25+
from posit.connect.external.snowflake import PositAuthenticator
26+
27+
ACCOUNT = os.getenv("SNOWFLAKE_ACCOUNT")
28+
WAREHOUSE = os.getenv("SNOWFLAKE_WAREHOUSE")
29+
30+
# USER is only required when running the example locally with external browser auth
31+
USER = os.getenv("SNOWFLAKE_USER")
32+
33+
# https://docs.snowflake.com/en/user-guide/sample-data-using
34+
DATABASE = os.getenv("SNOWFLAKE_DATABASE", "snowflake_sample_data")
35+
SCHEMA = os.getenv("SNOWFLAKE_SCHEMA", "tpch_sf1")
36+
TABLE = os.getenv("SNOWFLAKE_TABLE", "lineitem")
37+
38+
session_token = st.context.headers.get("Posit-Connect-User-Session-Token")
39+
auth = PositAuthenticator(
40+
local_authenticator="EXTERNALBROWSER", user_session_token=session_token
41+
)
42+
43+
con = snowflake.connector.connect(
44+
user=USER,
45+
account=ACCOUNT,
46+
warehouse=WAREHOUSE,
47+
database=DATABASE,
48+
schema=SCHEMA,
49+
authenticator=auth.authenticator,
50+
token=auth.token,
51+
)
52+
53+
snowflake_user = con.cursor().execute("SELECT CURRENT_USER()").fetchone()
54+
st.write(f"Hello, {snowflake_user[0]}!")
55+
56+
with st.spinner("Loading data from Snowflake..."):
57+
df = pd.read_sql_query(f"SELECT * FROM {TABLE} LIMIT 10", con)
58+
59+
st.dataframe(df)
60+
```
61+
"""
62+
1263
def __init__(
1364
self,
1465
local_authenticator: Optional[str] = None,

0 commit comments

Comments
 (0)