cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to connect Databricks to Snowflake using Python?

User16790091296
Contributor II
1 REPLY 1

Ryan_Chynoweth
Honored Contributor III

The open source spark connector for Snowflake is available by default in the Databricks runtime.

To connect you can use the following code:

# Use secrets DBUtil to get Snowflake credentials.
user = dbutils.secrets.get("<scope>", "<secret key>")
password = dbutils.secrets.get("<scope>", "<secret key>")
url = dbutils.secrets.get("<scope>", "<secret key>")
 
# snowflake connection options
options = {
  "sfUrl":  url,
  "sfUser": user,
  "sfPassword": password,
  "sfDatabase": "<database>",
  "sfSchema": "<schema>",
  "sfWarehouse": "<warehouse>"
}
 
# read data
df = (spark.read
  .format("snowflake")
  .options(**options)
  .option("dbtable", "<table name>")
  .load())

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.