1

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

1 Answers1

1

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.

aek
  • 1,370
  • 2
  • 10
  • 14
  • Thanks, this did indeed work. Sorry this a new account so I can upvote your comment (yet). – Nicolas Sanchez Jun 16 '23 at 19:33
  • @NicolasSanchez no worries. I am glad to know that it worked for you. You still can mark the answer as “accepted” though. It will help others too. – aek Jun 16 '23 at 20:55