liveBook · Manning

Snowpark Session

As explained in Snowflake Data Engineering

A Snowpark session is an object representing an authenticated connection through which Snowpark operations are constructed and submitted to Snowflake.

A Snowpark session represents the connection through which Python code establishes context in Snowflake and constructs operations for server-side execution. Create it with the Snowpark Session module and connection parameters such as account, user, role, warehouse, database, and schema. section 6.3.2

Use the session to:

  • Submit SQL with session.sql(); results remain lazily evaluated until an action such as collect(), count(), show(), or save_as_table(). section 6.3.4
  • Create data frames from local data and an explicit schema with create_dataframe(). section 6.5
  • Retrieve Snowflake tables through table(), join data frames, and publish results as tables or views. section 6.7
  • Close the session after use so it does not remain active. section 6.3.2

Joining pipeline tables

A session can retrieve ORDERS_STG and DIM_DATE as data frames, left-join delivery dates to calendar days, and create the ORDERS_HOLIDAY_FLG view. The resulting view exposes order data together with a holiday flag. section 6.7

Listing 6.3 Creating a session with the Snowflake account
# import Session from the snowflake.snowpark package
from snowflake.snowpark import Session
# create a dictionary with the connection parameters
connection_parameters_dict = {
    "account": "pqrstuv-ab12345", # replace with your Snowflake account
    "user": "my_user", # replace with your username
    "password": "my_pass", # replace with your password
    "role": "SYSADMIN",
    "warehouse": "BAKERY_WH",
    "database": "BAKERY_DB",
    "schema": "SNOWPARK"
}  
# create the session object
my_session = Session.builder.configs(connection_parameters_dict).create()
# close the session
my_session.close()

Use the session-creation listing as a runnable baseline: import Session, configure the connection, create my_session, and close it. Replace visible test credentials with configuration files or secrets for production use. section 6.3.2

How Snowflake Data Engineering covers it

How deep it goes
Explains connection configuration, lifecycle, SQL actions, data-frame access, joins, and view creation, without detailing authentication mechanisms.
Examples
Uses bakery tables, a holiday dimension, timestamp SQL, explicit schemas, joins, saved tables, and the ORDERS_HOLIDAY_FLG view.
What it assumes
Assumes an installed Snowpark Python package and Snowflake connection information, while demonstrating session creation from basic Python.
What you can do after
Apply it via Snowpark Python to query Snowflake, construct data frames, join tables, save results, create views, and close connections.
How it connects
Connects Snowpark Python with SQL commands, data frames, lazy evaluation, Snowflake tables, and views.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Snowflake Data Engineering. The section links point to the parts of the book it draws on.