I build up a connection to snowflake from python with snowpark session library using the authenticator externalbrowser. When I run the code then the browser opens and I type in my credentials. The python code is executing and I get the data from snowflake.
But this happens everytime when I run the python code. Is there a way to store authenticator information to use them multiple times?
I use the same authentication via externalbrowser with datagrip and I can use the authentication several hours.
from snowflake.snowpark import Session
connection_parameters = {
"account": "xyz",
"authenticator": "externalbrowser",
"user": "abcde",
"role": "role_one",
"warehouse": "tiny",
"database": "db1234"
}
# create session
session = Session.builder.configs(connection_parameters).create()
Yes, you can store authentication tokens using Snowflake's private key authentication instead of external browser. Here's how:
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
ALTER USER your_username SET RSA_PUBLIC_KEY='contents_of_rsa_key.pub';
from snowflake.snowpark import Session
connection_parameters = {
"account": "xyz",
"user": "abcde",
"private_key_path": "path/to/rsa_key.p8",
"role": "role_one",
"warehouse": "tiny",
"database": "db1234"
}
session = Session.builder.configs(connection_parameters).create()
This eliminates the need for browser authentication on each run.