0% found this document useful (0 votes)
7 views

Python Framework For Connecting To Snowflake

In this framework we can connect to snowflake and fetch the data from snowflake into python dataframe and also we can save into required format

Uploaded by

Laxman Gowda
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Framework For Connecting To Snowflake

In this framework we can connect to snowflake and fetch the data from snowflake into python dataframe and also we can save into required format

Uploaded by

Laxman Gowda
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import snowflake.

connector as sf
import pandas as pd

sf_conn_obj = sf.connect(
user = 'laxmanagwd',
password = 'Qwerty@123',
account = 'bk92069.ap-southeast-1',
warehouse = 'COMPUTE_WH',
schema = 'TPCH_SF1',
database = 'SNOWFLAKE_SAMPLE_DATA'
)

print(type(sf_conn_obj))
print(sf_conn_obj.account)

sf_cursor_obj = sf_conn_obj.cursor()
try:
# sf_cursor_obj.execute("select \
# current_database(), current_schema(), current_warehouse(), \
# current_version(), current_account(), current_client()")
sf_cursor_obj.execute("Select * from customer")
results_df = pd.DataFrame(sf_cursor_obj.fetchmany(5), columns=[desc[0] for desc
in sf_cursor_obj.description])
# one_row = sf_cursor_obj.fetchmany(5)
# for i in one_row:
# print(i)
finally:
sf_cursor_obj.close()

sf_conn_obj.close()
print(results_df)

output_csv_path = 'output_data.csv'
results_df.to_csv(output_csv_path, index=False)

print(f"Data saved to CSV file: {output_csv_path}")

You might also like