snowflake_utilities.create

Submodule create.py includes the following functions:

  • create_warehouse - creates a warehouse in Snowflake if it does not already exist

  • create_database - creates a database in Snowflake if it does not already exist

  • create_schema - creates a schema in Snowflake if it does not already exist

snowflake_utilities.create.create_database(conn: ~snowflake.connector.connection.SnowflakeConnection = <snowflake.connector.connection.SnowflakeConnection object>, database_name: str = 'mydb')[source]

Creates a database in Snowflake if it does not already exist.

Parameters:
connsnowflake.connector.connection.SnowflakeConnection

A connection to Snowflake

database_namestr

The name of the database to create

Returns:
NoneNone
snowflake_utilities.create.create_schema(conn: ~snowflake.connector.connection.SnowflakeConnection = <snowflake.connector.connection.SnowflakeConnection object>, schema_name: str = 'myschema')[source]

Creates a schema in Snowflake if it does not already exist.

Parameters:
connsnowflake.connector.connection.SnowflakeConnection

A connection to Snowflake

schema_namestr

The name of the schema to create

Returns:
NoneNone
snowflake_utilities.create.create_warehouse(conn: ~snowflake.connector.connection.SnowflakeConnection = <snowflake.connector.connection.SnowflakeConnection object>, warehouse_name: str = 'tiny_warehouse_mg')[source]

Creates a warehouse in Snowflake if it does not already exist.

Parameters:
connsnowflake.connector.connection.SnowflakeConnection

A connection to Snowflake

warehouse_namestr

The name of the warehouse to create

Returns:
NoneNone

snowflake_utilities.upload

Submodule upload.py includes the following functions:

  • upload_pandas_df_to_snowflake - uploads a Pandas DataFrame to Snowflake

snowflake_utilities.upload.upload_pandas_df_to_snowflake(data: ~pandas.core.frame.DataFrame = Empty DataFrame Columns: [] Index: [], warehouse_name: str = 'tiny_warehouse_mg', database_name: str = 'mydb', schema_name: str = 'myschema', table_name: str = 'mytable', if_exists: str = 'replace')[source]

Uploads a Pandas DataFrame to Snowflake.

Parameters:
datapd.DataFrame

The Pandas DataFrame to upload

warehouse_namestr

The name of the warehouse to use

database_namestr

The name of the database to use in Snowflake

schema_namestr

The name of the schema to use in Snowflake

table_namestr

The name of the table to use in Snowflake

if_existsstr

The action to take if the table already exists in Snowflake Options are ‘fail’, ‘replace’, ‘append’

Returns:
new_dfpd.DataFrame

The Pandas DataFrame that was pulled from Snowflake following the upload

snowflake_utilities.utils

Submodule utils.py includes the following functions:

  • get_snowflake_connection - returns a connection to Snowflake

  • check_resource_viable - checks if a resource type is viable (i.e. is the string a resource type in Snowflake)

  • print_resources - prints the resources in Snowflake

snowflake_utilities.utils.check_resource_viable(resource_type: str = 'WAREHOUSES')[source]

Checks if a resource type is viable (i.e. it is not a table).

Parameters:
resource_typestr

The type of resource to check

Returns:
is_viablebool

True if the resource type is viable, False otherwise

snowflake_utilities.utils.get_snowflake_connection()[source]

Returns a connection to Snowflake. Assuming the following environment variables are set: SNOWFLAKE_USERNAME - the username SNOWFLAKE_PASSWORD - the password SNOWFLAKE_ACCOUNT - the account name (the beginning of the URL when you log in to Snowflake)

Parameters:
NoneNone
Returns:
connsnowflake.connector.connection.SnowflakeConnection

A connection to Snowflake

snowflake_utilities.utils.print_resources(conn: ~snowflake.connector.connection.SnowflakeConnection = <snowflake.connector.connection.SnowflakeConnection object>, resource_type: str = 'WAREHOUSES')[source]

Prints the list of resources of a given type in Snowflake.

Parameters:
connsnowflake.connector.connection.SnowflakeConnection

A connection to Snowflake

resource_typestr

The type of resource to print (e.g. WAREHOUSES, DATABASES, SCHEMAS, TABLES)

Returns:
all_rowslist

A list of all rows returned by the query