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
