Sign inGet started
← Back to all guides

How to connect to Snowflake using SQLAlchemy

By Nick Barth

Updated on March 6, 2024

To connect to Snowflake using SQLAlchemy, you will need to install the Snowflake SQLAlchemy package and then set up your connection URI with your Snowflake account details. The URI typically includes your user, password, account, warehouse, database, and schema information. Below is a step-by-step guide expressed in Markdown:

  1. Install the Snowflake SQLAlchemy package by running:
pip install snowflake-sqlalchemy

2. Create a connection URI in the following format:

snowflake://<USER>:<PASSWORD>@<ACCOUNT_IDENTIFIER>/<DATABASE_NAME>/<SCHEMA_NAME>?warehouse=<WAREHOUSE>&role=<ROLE>

3. Use the URI to create an engine using SQLAlchemy:

from sqlalchemy import create_engine
engine = create_engine('<YOUR_CONNECTION_URI>')  

4. Now you can use the engine to execute queries against your Snowflake database.

connection = engine.connect()
results = connection.execute("SELECT * FROM your_table").fetchall()
connection.close()

Please ensure you replace `<YOUR_CONNECTION_URI>` with the actual connection URI created in step 2.

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