Snowflake Connector for Python

raw JSON →
1.12.0 verified Tue May 12 auth: no python install: draft quickstart: draft

The Snowflake Connector for Python provides a standard Python interface to connect to Snowflake, execute queries, and fetch results. It's the core driver for interacting with Snowflake from Python applications. The current stable version is 1.12.0, and the library is actively maintained with frequent releases, typically on a monthly or bi-monthly cadence.

pip install snowflake-connector-python
error Failed to build wheel for cryptography
cause The `cryptography` package, a dependency of `snowflake-connector-python`, requires specific system build tools (like C++ compilers or development headers) which are missing.
fix
Install the necessary build tools for your operating system (e.g., build-essential on Linux, XCode command line tools on macOS, or Visual C++ Build Tools on Windows), then retry pip install snowflake-connector-python. Often updating pip and setuptools first can help: python -m pip install --upgrade pip setuptools wheel.
error Failed to connect to DB: <account_name>.snowflakecomputing.com:443
cause This error indicates a network connectivity issue, an incorrect Snowflake account identifier, firewall blocking, or proxy misconfiguration preventing the client from reaching the Snowflake endpoint.
fix
Verify the Snowflake account identifier (e.g., myaccount.us-east-1 vs myaccount), check network connectivity, firewall rules, and proxy settings, ensuring the client can reach *.snowflakecomputing.com on port 443.
error Invalid username or password.
cause The provided username or password in the connection parameters is incorrect or does not match an existing Snowflake user.
fix
Double-check the username and password for typos, verify that the user exists, and ensure the credentials are correct; consider using key-pair authentication for robust credential management.
error snowflake.connector.errors.ProgrammingError: 002043 (02000): SQL compilation error:
cause The SQL query being executed contains a syntax error, refers to non-existent database objects (table, column), or has other issues preventing Snowflake from successfully compiling or executing it.
fix
Carefully review the SQL query for syntax errors, verify that all referenced tables, schemas, and databases exist and are accessible to the connecting user, and ensure correct object casing.
gotcha Strict Python Version Requirements
fix Ensure your Python environment is within the supported range (e.g., Python 3.10 to 3.13 for current 1.x versions). Check PyPI for the `Requires: Python` metadata.
gotcha Optional `pyarrow` dependency is critical for performance with Pandas
fix For optimal performance when fetching large datasets or using `fetch_pandas_all`, install `pyarrow` separately or use the `pandas` extra: `pip install "snowflake-connector-python[pandas]"`.
gotcha Snowflake account identifier format can be complex
fix The `account` parameter must be your full Snowflake account identifier, which can vary based on region and cloud provider (e.g., `myorg-myaccount.us-east-1.aws`). Consult your Snowflake administrator or documentation for the exact format.
breaking Significant changes in connection parameters and error handling from `0.x` to `1.x`
fix If migrating from an older `0.x` version, review the official documentation for `1.x` regarding updated connection parameter names (e.g., `account` instead of `host`) and the new error handling classes like `snowflake.connector.errors.ProgrammingError`.
breaking Building 'snowflake-connector-python' requires a C++ compiler.
fix Ensure a C++ compiler (like `g++` or `build-base` on Alpine Linux) is installed in your environment before attempting to install the package. For Alpine-based images, you typically need to run `apk add build-base`.
pip install "snowflake-connector-python[pandas]"
python os / libc variant status wheel install import disk
3.10 alpine (musl) pandas - - - -
3.10 alpine (musl) snowflake-connector-python - - - -
3.10 slim (glibc) pandas - - 2.63s 376M
3.10 slim (glibc) snowflake-connector-python - - 1.53s 88M
3.11 alpine (musl) pandas - - - -
3.11 alpine (musl) snowflake-connector-python - - - -
3.11 slim (glibc) pandas - - 3.62s 402M
3.11 slim (glibc) snowflake-connector-python - - 2.35s 93M
3.12 alpine (musl) pandas - - - -
3.12 alpine (musl) snowflake-connector-python - - - -
3.12 slim (glibc) pandas - - 4.28s 386M
3.12 slim (glibc) snowflake-connector-python - - 2.93s 85M
3.13 alpine (musl) pandas - - - -
3.13 alpine (musl) snowflake-connector-python - - - -
3.13 slim (glibc) pandas - - 3.94s 385M
3.13 slim (glibc) snowflake-connector-python - - 2.60s 84M
3.9 alpine (musl) pandas - - - -
3.9 alpine (musl) snowflake-connector-python - - - -
3.9 slim (glibc) pandas - - 2.87s 374M
3.9 slim (glibc) snowflake-connector-python - - 1.68s 88M

This quickstart demonstrates how to establish a basic connection to Snowflake using environment variables for credentials and execute a simple query. Remember to replace the placeholder environment variables with your actual Snowflake credentials for a successful connection. Proper resource cleanup is handled in the `finally` block.

import snowflake.connector
import os

# Set these environment variables before running, or replace with your actual credentials:
# export SNOWFLAKE_USER="your_username"
# export SNOWFLAKE_PASSWORD="your_password"
# export SNOWFLAKE_ACCOUNT="your_account_identifier" # e.g., 'yourorg-youraccount.us-east-1.aws'
# export SNOWFLAKE_WAREHOUSE="your_warehouse_name"
# export SNOWFLAKE_DATABASE="your_database_name"
# export SNOWFLAKE_SCHEMA="your_schema_name"

conn = None
cur = None

try:
    conn = snowflake.connector.connect(
        user=os.environ.get('SNOWFLAKE_USER', 'dummy_user'),
        password=os.environ.get('SNOWFLAKE_PASSWORD', 'dummy_password'),
        account=os.environ.get('SNOWFLAKE_ACCOUNT', 'dummy_account'),
        warehouse=os.environ.get('SNOWFLAKE_WAREHOUSE', 'dummy_warehouse'),
        database=os.environ.get('SNOWFLAKE_DATABASE', 'dummy_database'),
        schema=os.environ.get('SNOWFLAKE_SCHEMA', 'dummy_schema')
    )

    cur = conn.cursor()
    cur.execute("SELECT current_version()")
    one_row = cur.fetchone()
    print(f"Successfully connected. Snowflake version: {one_row[0]}")

except snowflake.connector.errors.ProgrammingError as e:
    print(f"Snowflake connection or query error: {e}")
    print("Please ensure environment variables (SNOWFLAKE_USER, SNOWFLAKE_PASSWORD, SNOWFLAKE_ACCOUNT, etc.) are correctly set.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    if cur:
        cur.close()
    if conn:
        conn.close()