Search code examples
pythonsnowflake-cloud-data-platformsingle-sign-on

Creating Snowpark Session using account with SSO - Snowflake connector method is not working


I'm working on a Snowpark project using the Python Snowflake API. My organization has setup Snowflake SSO authentication, so I need to use this method to login to my snowflake account.

To connect to Snowflake using your IDE and Python, you would use the Python connector (https://docs.snowflake.com/developer-guide/python-connector/python-connector-install#step-2-verify-your-installation).

I can easily authenticate with this method using the below code:

from snowflake.snowpark import Session
import snowflake.connector

ctx = snowflake.connector.connect(
user='<username>',
account='<account>',
authenticator='externalbrowser'
)

With this code what I'm getting is a snowflake.connector.connection.SnowflakeConnection object. I can access all its available attributes and methods (https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-api).

However, when using snowpark I need a snowflake.snowpark.Session object (https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-session#creating-a-session). In the documentation it is stated that

"To authenticate, you use the same mechanisms that the Snowflake Connector for Python supports."

The problem here is that I don't know how to "connect" my snowpark Session object to use the SSO that I setup with my python connector. I need it to perform all Snowpark operations leveraging the Snowpark API.

A similar question has been posted before but has not been answered: Creating Snowpark Session using account with SSO


Solution

  • Indeed, the same mechanism as for the Python connector should work for a Snowpark session.

    It should work as something like:

    connection_parameters = {
        "account": "accountname",
        "user": "username",
        "authenticator": "externalbrowser"
    }  
    new_session = Session.builder.configs(connection_parameters).create()  
    

    Doc reference.