Sign inGet started
← Back to all guides

Connecting to Snowflake from a Jupyter notebook

By Nick Barth

Updated on March 6, 2024

Connecting to Snowflake from a Jupyter notebook involves the use of Snowflake's Python connector.

Below is a general step-by-step guide:

  1. Install the Snowflake connector. In your Jupyter notebook, install the connector using the following command:
!pip install snowflake-connector-python

2. Import the connector. At the beginning of your script, import the connector with the import statement:

import snowflake.connector

3. Establish a connection. Create a connection object with your Snowflake account credentials:

conn = snowflake.connector.connect(
⁠
⁠    user='<your_username>',
⁠
⁠    password='<your_password>',
⁠
⁠    account='<your_account_url>',
⁠
⁠    warehouse='<your_warehouse>',
⁠
⁠    database='<your_database>',
⁠
⁠    schema='<your_schema>'
⁠
⁠)

4. Execute queries. With the connection established, you can execute reads and writes to your Snowflake instance:

cursor = conn.cursor()
⁠
⁠try:
⁠
⁠    cursor.execute('<YOUR_SQL_QUERY>')
⁠
⁠    for row in cursor:
⁠
⁠        print(row)
⁠
⁠finally:
⁠
⁠    cursor.close()

5. Close the connection. It's important to close the connection once your operations are complete:

conn.close()

Always ensure that your credentials are stored securely and not exposed in the Jupyter notebook to prevent unauthorized access to your Snowflake account.

Nick Barth

Product Engineer

Nick has been interested in data science ever since he recorded all his poops in spreadsheet, and found that on average, he pooped 1.41 times per day. When he isn't coding, or writing content, he spends his time enjoying various leisurely pursuits.

Follow Nick on LinkedIn and GitHub

That’s it, time to try Deepnote

Get started – it’s free
Book a demo

Footer

Solutions

  • Notebook
  • Data apps
  • Machine learning
  • Data teams

Product

Company

Comparisons

Resources

  • Privacy
  • Terms

© Deepnote