Skip to main content

A helpful package for making snowpark code easier to write and more legible

Project description

Snowpark-Utilities

Description

Snowpark Utilities is a set of Python tools aimed at easing much of the repetitive work around using Snowflake's Snowpark API. these tools aim make it easier to stand up new snowpark sessions or execute sql commands especialy in environments where multiple sessions are needed. The module contains functionality for users who want to directly feed credentails for authentication or those who are working with a tool like AWS secrets where credentils might be stored. The aim of this project is to make it faster and cleaner to stand up new snowpark projects without copy and pasting code from similar endeavors or combing through documentation.

init

if utilizing aws secrets to provider snowflake credentials, you must specify cloud_provider = "aws" or cloud_provider = "AWS" as well as the proper region name, access key id and secret access key

fetch_credentials_from_secrets(secret_name)

This function takes an AWS secret name as an input and returns the credentials in a dictionary format where they can be queried either for use in create_snowpark_session() or for other uses

create_snowpark_session(username, password, account, role, warehouse)

This function takes in the above five required inputs and returns a "session" variable which can be used for snowpark operations. if you were to, for example, have a "parent" and "child" snowflake account and needed sessions for both, you could run the following:

parent_session = create_snowpark_session('username', 'password', 'account', 'role', 'warehouse')
child_session = create_snowpark_session('username', 'password', 'account', 'role', 'warehouse')

now it's simple to differentiate execution between the two accounts

aws_create_snowpark_session(secret_name, role, warehouse)

This function is a version of create_snowpark_session() made explicitely for use with AWS Secrets. simply feed it the appropriate secret name and as long as the username is filed under the key name "username" password under "password" and account under "account" it will return a session. If you don't have this naming schema and still want to use secrets, it's simple to modify this function or fetch the credentials using fetch_credentials_from_secrets and parse the dictionary yourself

execute_sql(session, command)

An annoyance I've had with snowpark in terms of ease of use and code readability is that defining code and executing code are two distinctly different operations. you can always define a piece of SQL code for operation using session.sql("sql code") but executing requires a .collect() at the end of this line. This command takes in the given session and desired command and executes it all at once. if you wish to do anything with .to_pandas() you will still need to define that manualy but this works great for anything else and the function returns the .collect() so you could also run the function within a pd.Dataframe()

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

snowpark_utilities-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file snowpark_utilities-0.1.1.tar.gz.

File metadata

  • Download URL: snowpark_utilities-0.1.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for snowpark_utilities-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bba022c86714d1ab9fd54a804a505982e587a9065c1ccc7fdf77316fc30f770d
MD5 df5a7eeb95180897f8f3cb14546df380
BLAKE2b-256 952a89add605f6b1c39acd66451bc5d929e2f84d3955b5f7fc584cd921ea6c7d

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