A local client for conecting and working with Snowflake
Project description
shipyard-snowflake
The shipyard-snowflake
Python Package is a set of utility classes designed to streamline interactions with Snowflake, a cloud-based data warehousing platform. This package offers two main client classes, SnowflakeClient
and SnowparkClient
, each catering to different use cases and functionalities within the Snowflake ecosystem.
Table of Contents
Installation
You can install shipyard-snowflake
using pip
:
pip install shipyard-snowflake
Usage
SnowflakeClient
The SnowflakeClient class provides methods to interact with Snowflake using the Snowflake Python Connector. It supports functionalities such as authentication, data uploading, executing queries, and fetching results. Here's an example of how to use it:
import pandas as pd
from shipyard_snowflake import SnowflakeClient
# Initialize the SnowflakeClient with credentials
client = SnowflakeClient(
username="your_username",
pwd="your_password",
account="your_account_id",
warehouse="your_warehouse",
database="your_database",
schema="your_schema",
rsa_key="your_rsa_key", # Optional, use either rsa_key or pwd
role="your_role"
)
# Connect to Snowflake
connection = client.connect()
# Upload a DataFrame to Snowflake
df = pd.DataFrame(...) # Your DataFrame
success, nchunks, nrows, output = client.upload(
conn=connection,
df=df,
table_name="your_table_name",
if_exists="replace" # or append
)
# Fetch Query
query = "SELECT * FROM your_table_name"
result_df = client.execute_query(conn=connection, query=query)
# Execute Query
query = "DROP TABLE IF EXISTS SALES"
result_df = client.fetch(conn=connection, query = query)
# Close the connection
connection.close()
SnowparkClient
The SnowparkClient class allows interaction with Snowflake using Snowpark, a modern data processing and scripting framework. It enables data upload and some query execution capabilities. Here's an example of how to use it:
from shipyard_snowflake import SnowparkClient
# Initialize the SnowparkClient with credentials
client = SnowparkClient(
username="your_username",
pwd="your_password",
account="your_account_url",
warehouse="your_warehouse", # optional
database="your_database", # optional
schema="your_schema", # optional
role="your_role" # optional
)
# Connect to Snowflake using Snowpark
session = client.connect()
# Upload a DataFrame to Snowflake
import pandas as pd
df = pd.DataFrame(...) # Your DataFrame
client.upload(
session=session,
df=df,
table_name="your_table_name",
overwrite=True # False for append
)
# Close the session
session.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for shipyard_snowflake-0.1.2a0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c94ba58bee0fe5aa0e6b0d4ff854c6c45a191b6dd70e7ad9f5d47bd5d1f0e36f |
|
MD5 | 2ce2c71075e53e126a8d47efb0db5193 |
|
BLAKE2b-256 | d520b10cadf2a83f9f968476caa434420762cc4e0c536950954840d0f0ecbbfe |
Hashes for shipyard_snowflake-0.1.2a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f601f532ed4c04780f42f623840e6e6ed9a432d566db3014b5dae7be1c60da41 |
|
MD5 | 090f997d29ac079ddb97df21bcd36f63 |
|
BLAKE2b-256 | 84eefc2dedca56c72aed23a0dfcd6b30bb38998dfb2bafa3ab0fc04ae5354e22 |