This illustrate how to use the Snowflake Connector to perform standard Snowflake operations such as user login, database and table creation, warehouse creation, data insertion/loading, and querying. To interact with a Snowflake database through Python, either using the snowflake.connector or the sqlalchemy packages. Both packages supports a number of technologies when it takes to enable secure authentication to Snowflake via Python, but according to my experience two of the most popular options are the externalBrowser authentication and default authentication, therefore I will use these in my examples.
The sample code at the end of this topic combines the examples into a single, working Python program.
from ast import For
from multiprocessing import connection
from sqlite3 import connect
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
from snowflake.sqlalchemy import URL
url = URL(
account="us-east-1",
user='dbadeeds.com',
password="!",
database='DBA1',
schema='dbusers',
warehouse=' WH_DBA_SM_XS',
role= RL_DBA_ROLE,
authenticator='externalbrowser',
)
engine = create_engine(url)
#connection = engine.connect()
sql = '''select "name","login_name","created_on","comment" from dba1.dbusers where "name" = upper(ddeeds);'''
try:
connection = engine.connect()
res = connection.execute(sql).fetchall()
print(res)
#print(res., res.login_name, res.created_on)
finally:
connection.close()
engine.dispose()
Leave a comment