cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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
Esteemed Contributor

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())

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now