Before you start
6- A Snowflake account and a user you are allowed to log in as
- Someone with the rights to change that user in Snowflake (you or an administrator)
- Python installed on the machine that will run the code
- The Snowflake Connector for Python installed in your environment (follow the installation page of the official connector documentation)
- A local terminal where you can generate keys
- A secure place outside your code repository to store the private key file
Key pair authentication lets a Python program log in to Snowflake with a private key instead of a password. Snowflake holds the matching public key on the user, and your code proves it owns the private key.
The flow has three stages:
- Create a public key and a private key in a local terminal.
- Enroll the public key in Snowflake with a query.
- Use the private key in your Python code.
Version note. No version numbers are pinned in this guide. Before you start, check the version of the Snowflake Connector for Python and of Python that your environment uses, and read the matching pages of the official Snowflake documentation.
What this guide does not give you. The exact key generation commands, the exact SQL statement for enrolling the key, and the exact argument names of the Python connection call are not reproduced here. Take them from the official Snowflake documentation page on key pair authentication and from the Snowflake Connector for Python documentation. This avoids copying a command that does not match your version.
A warning about parameter names. Some tools that connect to Snowflake through a driver ask you to set the AUTHENTICATOR and PRIV_KEY_FILE parameters in an additional options field. Do not assume those names apply to the Python connector. Confirm the argument names in the connector documentation.
Step 1 of 7: Confirm access and permissions
Ask who can change your Snowflake user, and confirm the user you will connect as. Enrolling a public key changes that user, so you need the right to do it or an administrator who will.
Also decide whether the connection is for a person or for a service. A service that runs unattended should use its own user, so you can revoke it without affecting anyone else.
Step 2 of 7: Create the public and private key in a local terminal
Generate the key pair in your local terminal, using the commands from the official Snowflake key pair authentication page. The private key stays with you. Only the public key goes to Snowflake.
Decide at this point whether the private key file is protected by a passphrase. If it is, your Python code needs that passphrase later, so plan where it will come from.
Step 3 of 7: Store the private key outside your repository
Move the private key file to a location with restricted file permissions, outside any folder tracked by version control. Anyone who can read this file can log in as the user.
Step 4 of 7: Enroll the public key in Snowflake
Run the query from the official documentation in Snowflake to attach the public key to the user. This is how Snowflake learns which private key to trust for that user.
Use the public key only. Never paste the private key into a query.
Step 5 of 7: Use the private key in your Python code
Pass the private key to the Snowflake Connector for Python when you open the connection. Look up the argument names in the connector documentation, since the names differ between tools.
Read the key location and any passphrase from environment variables or a secret store, with placeholders such as YOUR_PRIVATE_KEY_PATH and YOUR_PASSPHRASE in any shared example. This keeps secrets out of source files.
Step 6 of 7: Run a trivial query to check the connection
Open the connection and run the simplest query you can, then close the connection. A returned row proves that authentication, the user and the account details are all correct.
Do this before you add real queries, so a failure points at the login and not at your SQL.
Step 7 of 7: Check that no password is involved
Confirm that your code contains no password and that nothing prompts for one. This shows the login really used the key pair and not a leftover setting.
Expected result
The Python program opens a connection to Snowflake without asking for a password. A trivial query returns a result, and the connection closes without an authentication error. The exact result format depends on the query you run and the connector you use.
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| Authentication fails when the connection opens | The public key was not enrolled, was enrolled on a different user, or does not match the private key your code loads. | Check which user the public key is attached to and that it is the user in your connection settings. If in doubt, generate a new pair and enroll the new public key again. |
| The private key file cannot be read | The path is wrong, the file permissions block your account, or the file is in a different format from the one the connector expects. | Check the path and the permissions. Compare the key format with the requirements in the Snowflake Connector for Python documentation. |
| Loading the key fails with a passphrase or decryption error | The key is protected by a passphrase that your code does not supply, or the passphrase is wrong. | Supply the correct passphrase from a secret store or environment variable, or generate a key without a passphrase if your policy allows it. |
| A parameter such as AUTHENTICATOR or PRIV_KEY_FILE is rejected in Python | Those names appear in the additional options of some driver based tools. The Python connector can use different argument names. | Look up the argument names in the Snowflake Connector for Python documentation and use those. |
| The login works on your machine but not on a server | The key file or the secrets were not deployed to the server, or the server cannot read them. | Deploy the private key through your secret management, set the path and passphrase there, and check file permissions on the server. |
Frequently asked questions
Can I connect to Snowflake from Python without a password?
Yes. With key pair authentication you create a key pair, enroll the public key in Snowflake and use the private key in your Python code.
What are the stages of key pair setup?
Create the public and private key in a local terminal, enroll the public key in Snowflake with a query, then use the private key in Python.
Do AUTHENTICATOR and PRIV_KEY_FILE work in Python?
Those names are used in the additional options of some driver based tools. For the Python connector, check the argument names in its official documentation.
Which key goes into Snowflake?
Only the public key. Keep the private key on your side and out of version control.
Where do I find the exact commands?
In the official Snowflake documentation on key pair authentication and the Snowflake Connector for Python documentation.
From Grokem: https://www.grokem.com/data/data-platforms/data-warehouses/how-to-connect-to-snowflake-with-a-key-pair-in-python-setup-and-checks







