Repository navigation
How to create Snowflake Notebook
Notebook is an interactive, web-based development environment built directly inside Snowflake (Snowsight) that allows data engineers, data scientists, and analysts to combine SQL, Python (Snowpark), and Markdown within a single, unified interface.
- Instead of switching between separate Jupyter Notebooks, local IDEs, and database GUIs, Snowflake Notebooks run natively within Snowflake's security perimeter, providing direct access to your data, warehouses, and container compute pools.
Snowpark is Snowflake’s developer framework that allows you to write and execute code in popular programming languages—such as Python, Java, and Scala—directly inside Snowflake, without needing to move data out of the data warehouse.
- Instead of writing pure SQL queries or exporting data to external Python/Spark clusters, Snowpark lets you process data using DataFrames and custom functions natively inside Snowflake’s elastic engine.
Altair is a declarative statistical visualization library for Python, built on top of the Vega-Lite JSON specification. It is designed to let you create informative, elegant, and interactive charts by declaring relationships between data columns and visual encoding channels (such as x-axis, y-axis, color, and size).
- Because it produces lightweight JSON chart definitions rather than static bitmap images, Altair is widely used in interactive environments like Snowflake Notebooks, Jupyter, Streamlit, and web dashboards.
snow://workspace/USER$BAO2902.PUBLIC.DEFAULT$/versions/head/Notebook_1.ipynb
This notebook performs exploratory data analysis on Fivetran delivery records, aggregates delivery counts, and visualizes execution performance metrics.
SELECT "PkgExecutionkey", "DeliveryKey", "_fivetran_deleted" FROM ELS_SOURCE_SYSTEMS_DB_DEV.SRC_NHE_INSIGHTS.DIMDELIVERY_DBT_FIVETRAN LIMIT 100;
import pandas as pd from snowflake.snowpark.context import get_active_session from snowflake.snowpark.functions import col, count
session = get_active_session()
df_delivery = session.table("ELS_SOURCE_SYSTEMS_DB_DEV.SRC_NHE_INSIGHTS.DIMDELIVERY_DBT_FIVETRAN")
df_summary = ( df_delivery .filter(col('"_fivetran_deleted"') == False) .group_by('"PkgExecutionkey"') .agg(count('"DeliveryKey"').alias("TOTAL_DELIVERIES")) .sort(col('"PkgExecutionkey"')) )
pd_df = df_summary.to_pandas() pd_df
import pandas as pd import altair as alt
total_keys = len(pd_df) max_deliveries = int(pd_df["TOTAL_DELIVERIES"].max()) if not pd_df.empty else 0
print(f"Total Execution Keys: {total_keys}") print(f"Max Deliveries in a Package: {max_deliveries}\n")
chart = ( alt.Chart(pd_df) .mark_bar() .encode( x=alt.X("PkgExecutionkey:N", title="Package Execution Key"), y=alt.Y("TOTAL_DELIVERIES:Q", title="Total Deliveries"), tooltip=["PkgExecutionkey", "TOTAL_DELIVERIES"] ) .properties( width=600, height=300, title="Total Deliveries by Package Execution Key" ) )
chart
from snowflake.snowpark.context import get_active_session
session = get_active_session()
session.use_database("ELS_SOURCE_SYSTEMS_DB_DEV") session.use_schema("SRC_NHE_INSIGHTS")
TARGET_TABLE = "ELS_SOURCE_SYSTEMS_DB_DEV.SRC_NHE_INSIGHTS.SUMMARY_DELIVERY_METRICS"
snowpark_df = session.create_dataframe(pd_df) snowpark_df.write.save_as_table(TARGET_TABLE, mode="overwrite")
print(f"Successfully wrote {len(pd_df)} rows to {TARGET_TABLE}")
Schedule a task
- Create a task that runs this file on a recurring basis.
- Task name: Notebook_1_task_63931D5F
- Owner role: ACCOUNTADMIN
- Location: ELS_SOURCE_SYSTEMS_DB_DEV.SRC_NHE_INSIGHTS
- Frequency: Daily at 01:20 PM (UTC+07:00) (Local time) Bangkok
- Advanced settings
- Code bundle name: CODE_BUNDLE_C1C1DF60
- Runtime variant: CPU
- Python version: Python 3.12
- Runtime version: v2.10
- Compute pool: SYSTEM_COMPUTE_POOL_CPU
- Query warehouse: COMPUTE_WH
- Artifact repositories: SNOWFLAKE.SNOWPARK.PYPI_SHARED_REPOSITORY
snow://workspace/USER$BAO2902.PUBLIC.DEFAULT$/versions/head/.snowconfig/Notebook_1.ipynb.yml
location: database: ELS_SOURCE_SYSTEMS_DB_DEV schema: SRC_NHE_INSIGHTS name: CODE_BUNDLE_C1C1DF60 role: ACCOUNTADMIN
🏠 Home • 🐙 Main GitHub Repository • 💼 LinkedIn Profile
Built by Bao Nguyen • Senior Data Engineer
-
Snowflake Features
-
Data Governance & Security
-
Applications & Semantics