How to connect to Snowflake¶
Install the Snowflake extra¶
pip install semolina[snowflake]
# or
uv add "semolina[snowflake]"
The Snowflake extra installs adbc-poolhouse[snowflake], which provides the ADBC
Snowflake driver and connection pooling.
Configure with .semolina.toml (recommended)¶
Create a .semolina.toml file in your project root:
# .semolina.toml
[connections.default]
type = "snowflake"
account = "xy12345.us-east-1"
user = "myuser"
password = "mypassword"
database = "analytics"
warehouse = "compute_wh"
# role = ""
# schema = ""
Field |
Type |
Required |
Description |
|---|---|---|---|
|
|
Yes |
Must be |
|
|
Yes |
Account identifier with region (e.g. |
|
|
Yes |
Snowflake username |
|
|
Yes |
Snowflake password |
|
|
No |
Default database |
|
|
No |
Compute warehouse name |
|
|
No |
Role to activate for the session |
|
|
No |
Default schema |
Then load and register the pool:
from semolina import register, pool_from_config
pool, dialect = (
pool_from_config()
) # reads [connections.default]
register("default", pool, dialect=dialect)
Tip
Use pool_from_config(connection="analytics") to load a named connection section
other than default.
Configure manually¶
When credentials come from a vault or secrets manager, construct the pool directly:
from adbc_poolhouse import SnowflakeConfig, create_pool
from semolina import register
config = SnowflakeConfig(
account="xy12345.us-east-1",
user="myuser",
password="mypassword",
database="analytics",
warehouse="compute_wh",
)
pool = create_pool(config)
register("default", pool, dialect="snowflake")
Run a query¶
Once a pool is registered, the query API works the same as any backend:
from semolina import SemanticView, Metric, Dimension
class Sales(SemanticView, view="sales"):
revenue = Metric()
country = Dimension()
cursor = (
Sales.query()
.metrics(Sales.revenue)
.dimensions(Sales.country)
.execute()
)
for row in cursor.fetchall_rows():
print(row.country, row.revenue)
Generated SQL¶
Snowflake SQL uses AGG() for metrics and double-quoted identifiers:
SELECT AGG("revenue"), "country"
FROM "sales"
GROUP BY ALL
See also¶
How to choose and configure a backend – compare connection patterns
How to connect to Databricks – connect to Databricks metric views
How to test application code with MockPool – test queries with
MockPool