Short and Sweet

High level steps of this process:

  • Defines a sql query using tables in your snowflake database
  • Creates a connection to Snowflake using the snoflake.connector library for python
  • Executes said query with the snowflake connection and converts the results to a pandas dataframe
  • Modifies the dataframe column headers (manual)
  • Creates an engine using sqlalchemy
  • Imports the dataframe backinto a new table in your snowflake db

Show me the code

Below is an easy way to connect a web app, in my case a Django web app (which I knew nothing about prior to last week so don’t base too much of your web application building aspirations on this post) to Snowflake (which i also have never really had any hands on experience with so tread lightly here as well).

Import

import pandas as pd
import snowflake.connector as sf
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

Create a dummy dataframe

x = [1,2,3]
y = [2,3,4]
df = pd.DataFrame([x, y], columns=['one', 'two', 'three'])

#django #python #snowflake

Connecting a Django Web App to a Snowflake Database
25.25 GEEK