snowflake-snowpark-dbt
Installation
SKILL.md
Snowflake Snowpark Python & dbt
This skill covers building production data transformation pipelines with Snowpark Python (Snowflake's server-side Python API) and with dbt using the dbt-snowflake adapter.
Workflow for a Snowpark or dbt Transformation
- Snowpark: open a session — Build a
Sessionfrom environment-scoped credentials, specifying role, warehouse, database, and schema explicitly. - Snowpark: express transforms with the DataFrame API — Prefer
.filter(),.select(),.group_by().agg(), and.join()over raw SQL strings for reusable pipeline code; DataFrames are lazily evaluated and only execute on.collect()/.show()/a write action. - Snowpark: push compute server-side — Use scalar UDFs for row-wise logic, vectorized (pandas) UDFs for ML inference, UDTFs when one input row produces multiple output rows, and stored procedures for multi-step server-side orchestration.
- dbt: model in layers — Staging models (
stg_*) rename and type-cast; mart models express business logic on top of staging. - dbt: choose a materialization —
viewfor cheap logic,tableonly when reads are frequent,incrementalfor large fact tables,dynamic_tablefor near-real-time freshness needs. - dbt: define sources and tests — Declare sources in
_sources.ymlwith freshness thresholds; addunique/not_nulltests on key columns. - dbt: run selectively — Use
dbt run --select model+(model and downstream) or+model(model and upstream) instead of full-project runs during iteration. - dbt: build and validate — Run
dbt build(run + test in dependency order) before merging, anddbt docs generateto keep documentation current.
Snowpark Python
Snowpark runs Python server-side inside a Snowflake warehouse — data never leaves Snowflake. Core abstractions: Session, DataFrame, UDF, UDTF, UDAF, and Stored Procedure.