Automating Python in Snowflake: Notebooks, Stored Procedures & ML Jobs with Tasks
“I have Python code — how do I automate it in Snowflake?” The answer depends on where your code lives. Is it in a Snowflake Notebook? A…
Automating Python in Snowflake: Notebooks, Stored Procedures & ML Jobs with Tasks

“I have Python code — how do I automate it in Snowflake?” The answer depends on where your code lives. Is it in a Snowflake Notebook? A Python code snippet in a stored procedure? Or a full Python file you want to run end-to-end?
This blog walks through all three paths — from the simplest click-and-schedule approach to full production pipelines. We use a single consistent example throughout: running inference from a model stored in the Snowflake Model Registry.
📁Code first? *Here it is!*
The Three Paths to Python Automation in Snowflake

One-Time Setup: Train Your Model and Push to the Registry Run train.ipynb notebook in Snowflake workspace once to train a simple Random Forest classifier on the Iris dataset and push it to the Snowflake Model Registry. After this step, the model lives in Snowflake — ready for anyone to load and use.
What are we automating? The Model Inference Code — All three automation paths below use this same inference logic. It loads the model from the registry, scores the input table, and writes predictions back to Snowflake.
from snowflake.snowpark.context import get_active_session
from snowflake.ml.registry import Registry
session = get_active_session()
reg = Registry(session=session, database_name="ML_LAB", schema_name="DATA")
model = reg.get_model("iris_classifier").version("v1")
input_df = session.table("ML_LAB.DATA.IRIS").drop("SPECIES")
predictions = model.run(input_df, function_name="predict")
predictions.write.save_as_table(
"ML_LAB.DATA.IRIS_PREDICTIONS",
mode="overwrite"
)
print("Inference complete. Results written to ML_LAB.DATA.IRIS_PREDICTIONS.")
Path 1: Snowflake Notebooks
A Snowflake Notebook is an interactive notebook that runs natively inside Snowflake. You can mix SQL, Python, and Markdown cells — and you can schedule them to run automatically.
Notebook Option A: Schedule via the Snowsight UI (Easiest)
The simplest path to automation requires zero SQL.
- Open
[inference.ipynb](https://github.com/sheena-n/Python-Code-Automation-In-Snowflake/blob/main/inference.ipynb) in Snowflake workspace - Click the Schedule button (top-right of the notebook)
- Set your frequency — every hour, daily at 7am, every Monday, etc.
- Choose a warehouse, location and task name → Save

Snowflake creates a Task behind the scenes automatically. Your notebook runs on schedule with no additional setup.
Best for: Analysts and data scientists who want automation without writing pipeline code.
Notebook Option B: Create a Task with EXECUTE NOTEBOOK PROJECT
When you need the notebook as a node inside a larger pipeline, use EXECUTE NOTEBOOK PROJECTin a Task. Run [automation.ipynb](https://github.com/sheena-n/Python-Code-Automation-In-Snowflake/blob/main/automation.ipynb)notebook code.
task_name = "execute_inference_notebook"
iris_task = Task(
task_name,
definition="""EXECUTE NOTEBOOK PROJECT ML_LAB.DATA.NOTEBOOK_PROJECT_E341A9AC
MAIN_FILE = 'inference.ipynb'
COMPUTE_POOL = 'CPU_POOL'
QUERY_WAREHOUSE = 'COMPUTE_WH'
RUNTIME = 'V2.2-CPU-PY3.11'""",
warehouse=warehouse_name,
schedule=Cron("0 7 * * *", "UTC")
)
tasks.create(iris_task, mode="or_replace")
Best for: Engineers who want notebooks as steps in a Task DAG alongside SQL transforms or other procedures.
Path 2: Python Code Snippet — Stored Procedure + Task
Sometimes your inference logic doesn’t need to live in a notebook at all — you just want a schedulable Python function. The Snowflake answer is a Python Stored Procedure — A stored procedure wraps your Python function inside a Snowflake object. You invoke it with CALL my_proc(), which means Tasks can trigger it natively — no notebook required. Refer the notebook Stored_procedure.ipynb.
CREATE OR REPLACE PROCEDURE ML_LAB.DATA.sproc_inference()
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = '3.10'
PACKAGES = ('snowflake-ml-python', 'snowflake-snowpark-python')
HANDLER = 'run_inference'
AS
$$
from snowflake.ml.registry import Registry
def run_inference(session):
reg = Registry(session=session, database_name="ML_LAB", schema_name="DATA")
model = reg.get_model("iris_classifier").version("v1")
input_df = session.table("ML_LAB.DATA.IRIS").drop("SPECIES")
predictions = model.run(input_df, function_name="predict")
predictions.write.save_as_table(
"ML_LAB.DATA.IRIS_PREDICTIONS",
mode="overwrite"
)
return "Inference complete. Results written to ML_LAB.DATA.IRIS_PREDICTIONS."
$$;
Best for: Data engineers productionalising ML pipelines; logic that needs to be callable from SQL, applications, or other workflows.
Chain Multiple Tasks: Build DAG
Real pipelines have dependencies — refresh the data first, then run inference, then send a summary. Chain tasks into a Snowflake **Directed Acyclic Graph (DAG)**
Path 3: Python Files — ML Jobs + Stored Procedure + Task
What if your inference logic lives in a **.py file — a script checked into Git, a large batch job, or code that's too complex for a stored procedure? This is where Snowflake ML Jobs** come in.
What is an ML Job? An ML Job runs a Python file on Snowpark Container Services compute — purpose-built for ML workloads. Think of it as [python inference.py](https://github.com/sheena-n/Python-Code-Automation-In-Snowflake/blob/main/inference.py) running inside Snowflake's security perimeter, with access to your data and models, on managed scalable compute. Wrap an ML job in a stored procedure and attach it to Task.
CREATE OR REPLACE PROCEDURE ML_LAB.DATA.directory_inference_ml_job()
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = '3.10'
PACKAGES = ('snowflake-ml-python', 'snowflake-snowpark-python')
HANDLER = 'run'
AS
$$
from snowflake.ml.jobs import submit_directory
def run(session):
ml_job_dr = submit_directory(
"@ML_LAB.DATA.prod_code/",
"CPU_POOL",
entrypoint="inference.py",
stage_name="ML_LAB.DATA.payload_stage",
session=session,
)
ml_job_dr.wait()
return f"Job {ml_job_dr.id} finished with status: {ml_job_dr.status}"
$$;
Best for: ML engineers with GPU training workloads, containerised applications, or Python scripts too large or complex for a stored procedure.
Putting It All Together: When to Use What

Next Steps & Docs
- *Schedule a Notebook*
- *Task Graphs (DAGs)*
- *Python Stored Procedures*
- *ML Jobs*
- *Snowflake Model Registry*
Thank you for your time! It’s time to move files into production in Snowflake ;)
메타데이터
- post_id
- d0b7ff3ed5a8
- slug
- automating-python-in-snowflake-notebooks-stored-procedures-ml-jobs-with-tasks-d0b7ff3ed5a8
- url
- https://medium.com/snowflake/automating-python-in-snowflake-notebooks-stored-procedures-ml-jobs-with-tasks-d0b7ff3ed5a8
- canonical_url
- https://medium.com/snowflake/automating-python-in-snowflake-notebooks-stored-procedures-ml-jobs-with-tasks-d0b7ff3ed5a8
- author_url
- https://medium.com/@sheena.nasim_62602
- status
- ok
- fetched_at
- 2026-06-22 17:31:34