snowflake.snowpark.functions.udf_init_once

snowflake.snowpark.functions.udf_init_once(func: Callable) Callable[source]

Mark a function to be executed once during pre-fork initialization.

This decorator has the same signature as the server-side _snowflake.udf_init_once. It is a no-op for local invocation. Functions decorated with @udf_init_once run in the head worker process before individual workers are forked. The initialized state (e.g., loaded models, computed lookup tables) is shared across all workers via Copy-On-Write.

The decorated function must:
  • Accept zero arguments

  • Be a callable (function, lambda, or callable object)

Multiple @udf_init_once functions are executed in the order they are defined.

Example:

from snowflake.snowpark.functions import udf_init_once

model = None

@udf_init_once
def load_model():
    global model
    model = 42

Use this decorator in handler files registered via register_from_file(). On the Snowflake server the _snowflake.udf_init_once implementation is used instead; this client-side definition provides the same API so that handler files can be tested locally.

Parameters:

func – The init function to decorate. Must be callable and accept zero arguments.

Returns:

The decorated function, unchanged.