-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathcustom_cred_provider.py
More file actions
33 lines (26 loc) · 925 Bytes
/
custom_cred_provider.py
File metadata and controls
33 lines (26 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# please pip install databricks-sdk prior to running this example.
from databricks import sql
from databricks.sdk.oauth import OAuthClient
import os
oauth_client = OAuthClient(
host=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
client_id=os.getenv("DATABRICKS_CLIENT_ID"),
client_secret=os.getenv("DATABRICKS_CLIENT_SECRET"),
redirect_url=os.getenv("APP_REDIRECT_URL"),
scopes=["all-apis", "offline_access"],
)
consent = oauth_client.initiate_consent()
creds = consent.launch_external_browser()
with sql.connect(
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
credentials_provider=creds,
) as connection:
for x in range(1, 5):
cursor = connection.cursor()
cursor.execute("SELECT 1+1")
result = cursor.fetchall()
for row in result:
print(row)
cursor.close()
connection.close()