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 |
Note
database and warehouse are optional for the query pool: a fully-qualified
view name supplies the database, and the warehouse can fall back to your Snowflake
user’s default. semolina codegen is stricter and requires both – see
How to configure codegen credentials.
Connection pooling is tuned with the shared pool_size, max_overflow,
timeout, and recycle fields, documented under
Common fields.
Then build and register an engine:
from semolina import register, create_engine
register(
"default", create_engine("default")
) # reads [connections.default]
Tip
Use create_engine("analytics") to load a named connection section other
than default.
Configure manually¶
When credentials come from a vault or secrets manager, pass a config object to
create_engine():
from adbc_poolhouse import SnowflakeConfig
from semolina import register, create_engine
engine = create_engine(
SnowflakeConfig(
account="xy12345.us-east-1",
user="myuser",
password="mypassword",
database="analytics",
warehouse="compute_wh",
)
)
register("default", engine)
Run a query¶
Once an engine 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 query code without a warehouse – test queries with a local DuckDB backend