Pro ยท Lesson 9 of 13

Snowpark Python

DataFrames, Python UDFs, and stored procedures run where the data already lives.

Sign in to save your place.

Picture it this way

Snowpark is a remote control. The Python on your laptop describes the work. Snowflake's warehouse does the work next to the table, so you are not downloading a million rows to add them up. A UDF is one small Python function the SQL engine can call per value. A procedure is a Python function that can run several statements and hand a result back.

A session and a DataFrame

The snowflake-snowpark-python package creates a session with an account identifier, a user, a role, a warehouse, a database, and a schema. Prefer key-pair authentication over embedding a password in a file. The DataFrame API builds a plan. show() or collect() is what sends it.

Snowpark code runs on a warehouse. A Snowpark-optimized warehouse is the documented choice when the job needs more memory, such as model training. Ordinary filters and group-bys are fine on a Standard warehouse. The Python still cannot see a table your role cannot select.

UDFs and procedures

A Python UDF is created with LANGUAGE PYTHON, a RUNTIME_VERSION your account currently allows, and a HANDLER. Do not assume 3.11 is enabled. In Snowsight, check the Python versions the account offers and put that version in the statement. Packages you name must exist in the Snowflake Anaconda channel or be uploaded to a stage.

A stored procedure receives a Snowpark session as its first handler argument. It can query tables and return a string, a variant, or a table, depending on how you declare it. Procedures are on every edition, in Python, Java, Scala, JavaScript, and SQL.

Push filters into the DataFrame before you collect(). Collecting an entire fact table into the client defeats the point of the warehouse.

CREATE OR REPLACE FUNCTION double_qty(qty NUMBER)
  RETURNS NUMBER
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.11'
  HANDLER = 'double_qty'
AS
$$
def double_qty(qty):
    if qty is None:
        return None
    return qty * 2
$$;

What this lesson will not pretend

The RUNTIME_VERSION in the sample is a placeholder. If the create fails, the error is telling you the account does not offer that version. Change the string. Do not keep retrying a version the error rejected.

Snowpark Container Services and Streamlit in Snowflake exist and are listed in the edition matrix. They are different products from a DataFrame script. This lesson does not deploy a container.

Python that runs next to the data

Snowpark code looks like pandas but the work happens inside Snowflake, not on your laptop.

  1. Your PythonNotebook or script
  2. DataFrame planTurned into SQL, not yet run
  3. WarehouseRuns the SQL near the data
  4. Python UDFYour function, callable from SQL

Step 1 of 3DataFrame calls do not download data. Each call adds to a plan that Snowpark turns into SQL.

df = session.table("orders").filter(col("amount") > 100)

Lab: a function and a DataFrame script

Run the SQL function in a worksheet after you replace the runtime version if needed. The Python is for your machine, with the Snowpark package installed. Fill the account identifier from Snowsight. Use a key file rather than a password if you already have one. The script only counts rows for one region.

-- Worksheet. Replace the runtime version if your account rejects 3.11.
CREATE OR REPLACE FUNCTION double_qty(qty NUMBER)
  RETURNS NUMBER
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.11'
  HANDLER = 'double_qty'
AS
$$
def double_qty(qty):
    if qty is None:
        return None
    return qty * 2
$$;
SELECT double_qty(amount) FROM orders;

# Local Python, after: pip install snowflake-snowpark-python
from snowflake.snowpark import Session
from snowflake.snowpark.functions import col

session = Session.builder.configs({
    "account": "<org>-<account>",
    "user": "<user>",
    "private_key_file": "<path-to-key.p8>",
    "role": "SYSADMIN",
    "warehouse": "LEARN_WH",
    "database": "LEARN_DB",
    "schema": "PUBLIC",
}).create()

west = session.table("orders").filter(col("region") == "west")
print(west.count())
session.close()

Concept summary

Knowledge check

Where does a Snowpark DataFrame aggregation run?

What should you do if CREATE FUNCTION rejects RUNTIME_VERSION 3.11?

What is the first argument of a Python stored-procedure handler?

Official sources

Checked against Snowflake documentation in October 2026. Product behavior still depends on your edition, cloud, and region.