Chalk home page
Docs
API
CLI
  1. Integrations
  2. Snowflake

Chalk supports Snowflake as a SQL source. You can configure the Snowflake-specific options using the SnowflakeSource.__init__ args. Alternately, you can configure the source through your dashboard.

From the dashboard

Add Snowflake

Add a Snowflake integration. These parameters will also be available as environment variables.

Snowflake
Environment

Learn more about Chalk's Snowflake Integration


Single Integration

If you have only one Snowflake connection that you’d like to add to Chalk, you do not need to specify any arguments to construct the source in your code.

from chalk.sql import SnowflakeSource

snowflake = SnowflakeSource()

@online
def fn(...) -> ...:
    return snowflake.query(...).first()

Multiple Integrations

Chalk's injects environment variables to support data integrations. But what happens when you have two data sources of the same kind? When you create a new data source from your dashboard, you have an option to provide a name for the integration. You can then reference this name in the code directly.
from chalk.sql import SnowflakeSource

risk = SnowflakeSource(name="RISK")
marketing = SnowflakeSource(name="MARKETING")

@online
def risk_resolver(...) -> ...:
    return risk.query(...).first()

@online
def marketing_resolver(...) -> ...:
    return marketing.query(...).first()
Named integrations inject environment variables with the standard names prefixed by the integration name. For example, if your integration is called RISK, then the variable SNOWSQL_SCHEMA will be injected as RISK_SNOWSQL_SCHEMA. The first integration of a given kind will also create the un-prefixed environment variable (ie. both SNOWSQL_SCHEMA and RISK_SNOWSQL_SCHEMA).

Environment Variables

You can also configure the integration directly using environment variables on your local machine or from those added through the generic environment variable support.

import os
from chalk.sql import SnowflakeSource

snowflake = SnowflakeSource(
    db=os.getenv("SNOWSQL_DATABASE"),
    schema=os.getenv("SNOWSQL_SCHEMA"),
    role=os.getenv("SNOWSQL_ROLE"),
    warehouse=os.getenv("SNOWSQL_WAREHOUSE"),
    user=os.getenv("SNOWSQL_USER"),
    password=os.getenv("SNOWSQL_PWD"),
    account_identifier=os.getenv("SNOWSQL_ACCOUNT_IDENTIFIER")
)

@online
def resolver_fn(...) -> ...:
    return snowflake.query(...).first()