Python Connector for Snowflake

Connecting to Snowflake - Python Connector for Snowflake

Connecting to Snowflake

To establish a connection to Snowflake, import the connector and authenticate using basic, OAuth 2.0, or key pair authentication.

  1. Import the Snowflake connector module.
    import devart.snowflake as snowflake
  2. Connect to your Snowflake environment using the connect() module method and obtain a connection object.

    You can connect to Snowflake using either basic authentication, OAuth 2.0 authentication, or key pair authentication.

    Basic authentication

    For basic authentication, provide the Snowflake server URL, user name, and password.

    my_connection = snowflake.connect(
        Domain="<your_server_url>",
        UserId="<your_username>",
        Password="<your_password>",
        Database="<your_database>"
    )

    Replace the placeholders with your actual connection values. For more information, see Connection parameters.

    OAuth 2.0 authentication

    For OAuth 2.0 authentication, provide the Snowflake server URL and your OAuth client ID and client secret.

    response = snowflake.signin(
        Domain="<your_server_url>",
        ClientId="<your_client_id>",
        ClientSecret="<your_client_secret>"
    )
    my_connection = snowflake.connect(
        Domain="<your_server_url>",
        Authentication="OAuth",
        ClientId="<your_client_id>",
        ClientSecret="<your_client_secret>",
        RefreshToken=response["Refresh Token"],
        Database="<your_database>"
    )

    Replace the placeholders with your actual connection values. For more information, see Connection parameters and Obtaining credentials for OAuth 2.0 authentication.

    Key pair authentication

    For key pair authentication, provide the Snowflake server URL, user name, and private key (with its passphrase, if the key is encrypted).

    my_connection = snowflake.connect(
        Authentication="KeyPair",
        Domain="<your_server_url>",
        UserId="<your_username>",
        Database="<your_database>",
        Passphrase="<your_passphrase>",
        PrivateKey="<your_private_key>"
    )

    Replace the placeholders with your actual connection values. For more information, see Connection parameters and Obtaining credentials for key pair authentication.

© 2022-2026 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback