0

I need to build a solution for a Use Case and I am still a bit of a novice on Python capabilities for version 3.9.9.

Use Case:

  • User Billy wants to run a script against a Snowflake server Azure database, call it sandbox, using a his own python script on his local machine.
  • Billy's python script, to keep connection settings secure, needs to call a snowflake_conn.py script, which is located in another network folder location (\abs\here\is\snowflake_conn.py), and pass arguments for DB & Schema.
  • The call will return a connection to Snowflake Billy can use to run his SQL script.

I am envisioning something like:

import pandas as pd
import snowflake_conn # I need to know how to find this in a network folder, not local.
# and then call the custom conn function 
snowflake_connect('database','schema') 
# where it returns the snowflake.connector.connect.cursor() as sfconn 
conn1 = sfconn.conn()
qry = r'select * from tablename where 1=1'

conn1.execute(qry)
df = conn1.fetch_pandas_all()

I saw something like this..but that was from back in 2016 and likely prior to 3.9.9.

import sys
sys.path.insert(0, "/network/modules/location") # OR "\\abs\here\is\" ??
import snowflake_conn

That snowflake_conn.py file uses a configparser.ConfigParser() .read() command to open a config.ini file in the same folder as the snowflake_conn.py script.

I am following the instructions in another stackoverflow question, link below that is 4 years old, to help get the config.ini setup completed.

import my database connection with python

I also found this link, which seems to also point to only a local folder structure, not network folder. https://blog.finxter.com/python-how-to-import-modules-from-another-folder/

Eventually I want to try to encrypt the .ini file to protect the contents of that .ini file for increased security, but not sure where to start on that yet.

Jim
  • 67
  • 2
  • 10
  • Have you tried to run the code you found? Did you get any errors or unexpected results? – Jan Wilamowski Dec 28 '21 at 04:33
  • Hey @JanWilamowski. I did find a solution that works. I was able to source through the network using the Windows Systems mapped drive to locate the file and even export CSV files to another location. So that worked. The .ini file encryption I have not resolved. – Jim Mar 03 '22 at 16:49
  • Currently I am trying to find a solution on DF's where you compare two DF's and then only export the Left joined table results where it does not match the target. So DF1 being SQL server and DF2 being Snowflake. I only want DF1 results based on no matches (including not exists) to DF2. https://stackoverflow.com/questions/67682484/compare-two-data-frames-and-get-only-non-matching-values-with-index-and-column-n/71339214#71339214 – Jim Mar 03 '22 at 16:51

0 Answers0