Skip to main content

This package has been built to help developers build applications using snowflake quickly

Project description

snowflake-python-sdk

snowflake sdk for python

This package has been built to help developers build applications using snowflake quickly. below are some examples on how to work with this package

create a snowflake connection

You can create the connection using either a private key or a password. The connection details will need to be upated in the conf.ini file

sample code

Connecting to snowflake:

The below piece of code conects to snowflake and returnd the connection, statuscode and statusmessage:

from utilities.sf_operations import snowflakeconnection

connection = snowflakeconnection(profilename ='snowflake_host')
sfconnectionresults = connection.get_snowflake_connection()

sfconnection = sfconnectionresults.get('connection')
statuscode = sfconnectionresults.get('statuscode')
statusmessage = sfconnectionresults.get('statusmessage')

print(sfconnection,statuscode,statusmessage)

Execute a query in snowflake:

The below piece of code executes a query in snowflake

from utilities.sf_operations import snowflakeconnection
connection = snowflakeconnection(profilename ='snowflake_host')
sfconnectionresults = connection.get_snowflake_connection()

sfconnection = sfconnectionresults.get('connection')
statuscode = sfconnectionresults.get('statuscode')
statusmessage = sfconnectionresults.get('statusmessage')

querystring = "select * from sales;"
queryresult = connection.execute_snowquery(sfconnection,querystring)

queryid = queryresult.get('queryid') #This is the query id in SF
executionresult = queryresult.get('result')
statuscode = queryresult.get('statuscode')
statusmessage = queryresult.get('statusmessage')

print (queryid,statuscode,statusmessage)
for results in executionresult:
    print(results)

sfconnection.close()

Execute a query in snowflake in asynchrouos mode:

This uses the same function but with asyncflag as true

from utilities.sf_operations import snowflakeconnection
connection = snowflakeconnection(profilename ='snowflake_host')
sfconnectionresults = connection.get_snowflake_connection()

sfconnection = sfconnectionresults.get('connection')
statuscode = sfconnectionresults.get('statuscode')
statusmessage = sfconnectionresults.get('statusmessage')

#print(sfconnection,statuscode,statusmessage)

querystring = "select * from ADMCOE_SALES;"
queryresult = connection.execute_snowquery(sfconnection,querystring,asyncflag=True)

queryid = queryresult.get('queryid')
executionresult = queryresult.get('result')
statuscode = queryresult.get('statuscode')
statusmessage = queryresult.get('statusmessage')

Execute a snowflake script in snowflake:

This feature can be used to execute a script file with one or more snowflake queries

from utilities.sf_operations import snowflakeconnection
connection = snowflakeconnection(profilename ='snowflake_host')
sfconnectionresults = connection.get_snowflake_connection()

sfconnection = sfconnectionresults.get('connection')
statuscode = sfconnectionresults.get('statuscode')
statusmessage = sfconnectionresults.get('statusmessage')

#print(sfconnection,statuscode,statusmessage)

filename = "D://script.sql"
queryresult = connection.execute_stream(sfconnection,filename)

executionresult = queryresult.get('result')
statuscode = queryresult.get('statuscode')
statusmessage = queryresult.get('statusmessage')

for cursor in executionresult:
    for ret in cursor:
        print(ret)

print (executionresult,statuscode,statusmessage)

sfconnection.close()

Below features are currently in development progress

  1. Put file to a stage after splitting into multiple files
  2. Compress files before putting them to stage
  3. Archive files after putting them to stage

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snowflake-python-sdk-1.0.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

snowflake_python_sdk-1.0.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file snowflake-python-sdk-1.0.0.tar.gz.

File metadata

  • Download URL: snowflake-python-sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for snowflake-python-sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9167bd0089e35102d52c805c27341af4febd65951dc6c951a0ef6a637f2809da
MD5 d7415034c45a89eb8a12f2b111f7d0c1
BLAKE2b-256 4e626c78917b0069b361df5997ef3ce5563a0d142deaf07d322147453da19c56

See more details on using hashes here.

File details

Details for the file snowflake_python_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: snowflake_python_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for snowflake_python_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e735287f02a06270a937e8e81e6ca5c1313d2f14c7ee6d94fe3042817e2244a1
MD5 c0877e329482ba293f948147f87a6369
BLAKE2b-256 e73e78d44bf0c901f25bd2f7c7f97d22d8420f36dbe107d71820b7f833f822d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page