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:
- 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.