EXECUTE NOTEBOOK PROJECT

statementsupportedContainer services & dev tooling

docs.snowflake.com ↗

Note Notebook Project Objects have been renamed to Code Bundles. The NOTEBOOK PROJECT grammar on this page continues to work, including inside existing tasks and schedules. For the current command and its new capabilities, see EXECUTE CODE BUNDLE and Snowflake Code Bundles. Executes a notebook stored in a notebook project (NPO). This command runs the notebook in a non-interactive (headless) mode and is useful for CI/CD pipelines and other orchestrated workflows where you want to pass parameters or lock dependency versions for repeatable runs. The command can be run from: - SQL files. - Other Snowflake executables (Tasks). - External orchestrators that issue SQL (for example, Airflow, Prefect, Dagster, CI/CD systems). The command runs the notebook file you specify as MAIN_FILE using the runtime, compute pool, warehouse, and external access integrations you configure. Important Before triggering a non-interactive run, ensure that your notebook sets its execution context (database and schema) or uses fully qualified object names. For more information, see Editing and running notebooks in Workspaces. See also: CREATE NOTEBOOK PROJECT, CREATE TASK, CI/CD workflow scenario, Observability and logging for Notebooks in Workspaces, Running notebooks with parameters, Using secrets in Notebooks in Workspaces

Syntax

supportedpartialnot supportednot scored

EXECUTE NOTEBOOK PROJECT <database_name>.<schema_name>.<project_name>
  MAIN_FILE = 'notebook.ipynb'
  COMPUTE_POOL = '<compute_pool_name>'
  QUERY_WAREHOUSE = '<warehouse_name>'
  RUNTIME = '<runtime_version>'
  [ ARGUMENTS = '<arg> [ <arg> ... ]' ]
  [ REQUIREMENTS_FILE = '<path/to/requirements.txt>' ]
  [ ARTIFACT_REPOSITORIES = ( <repository_name> [ , ... ] ) ]
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
  [ SECRETS = ( <database_name>.<schema_name>.<secret_name> [ , ... ] ) ];

Parameters

NameRequiredDescription
database_name.schema_name.project_namerequiredFully qualified identifier of the notebook project to execute. Must reference an existing notebook project created with CREATE NOTEBOOK PROJECT. Must be fully qualified unless it resides in the current DATABASE and SCHEMA. For more information, see Identifier requirements.
MAIN_FILE = 'notebook_file_name.ipynb'requiredSpecifies the main notebook file within the workspace to execute (path/to/notebook.ipynb). Must be an .ipynb notebook file located in the workspace referenced by the project. The path is relative to the workspace root.
COMPUTE_POOL = 'compute_pool_name'requiredSpecifies the compute pool used when executing the notebook on a Container Runtime. Required when the notebook runtime uses Snowpark Container Services.
QUERY_WAREHOUSE = 'warehouse_name'requiredSpecifies the virtual warehouse used for executing SQL and Snowpark queries from the notebook. Required if the notebook performs SQL or Snowpark operations and no warehouse is otherwise configured. When using container runtimes, the warehouse handles query pushdown; Python executes on the compute pool.
RUNTIME = 'runtime_version'requiredSpecifies the runtime image or version for executing the notebook (for example, '1.0' or '2.2-CPU-PY3.11'). Determines the Python version and execution environment used for the notebook execution. Corresponds to a Container Runtime image (CPU or GPU) or warehouse runtime variant.
ARGUMENTS = 'arg [ arg ... ]'optionalOptionally passes arguments to the notebook at runtime, which appear as command-line arguments in the sys.argv list. Arguments are useful for making notebook logic dynamic (for example, selecting an environment such as --env prod). Specify all arguments as a single quoted string, separating individual arguments with whitespace. In a Python cell, access the arguments using sys.argv[0] for the notebook name, sys.argv[1] for the first argument, and so on. The value must be a string literal or a SQL variable reference such as :my_var. Function calls and other expressions aren’t supported. For an example of passing a value computed at runtime, see Pass arguments computed at runtime. The value must be a string. Passing a non-string expression is interpreted as NULL. The ARGUMENTS syntax differs between the two commands: EXECUTE NOTEBOOK PROJECT takes a single string, while EXECUTE CODE BUNDLE takes a parenthesized list of strings. Examples:Copy code ARGUMENTS = '--env prod'; Copy code import sys print(sys.argv)
REQUIREMENTS_FILE = '<path/to/requirements.txt>'optionalOptionally specifies a requirements.txt file in a workspace or on a stage to pre-install exact versions of libraries (such as pandas or scikit-learn) and other Python dependencies before notebook execution. Pinning dependencies is critical for idempotency and helps make notebook runs more repeatable, reducing errors caused by changes in library versions. The file must be accessible to the executing role.
EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )optionalSpecifies one or more external access integrations that the notebook can use during execution. Required when the notebook makes outbound network calls (for example, to external APIs). Each integration name must reference an existing external access integration. Multiple external access integrations can be specified in a comma-separated list inside the parentheses. Example:Copy code EXTERNAL_ACCESS_INTEGRATIONS = (http_eai, s3_eai); Note The Snowflake-managed PyPI network rule SNOWFLAKE.EXTERNAL_ACCESS.PYPI_RULE is only accessible to the ACCOUNTADMIN role. Consequently, using this rule in an External Access Integration (EAI) for notebook objects or scheduled tasks may cause them to fail. To avoid this, create a user-defined network rule for PyPI and reference it in your external access integration. For more information, see Snowflake-managed egress network rules.
SECRETS = ( database_name.schema_name.secret_name [ , ... ] )optionalOptionally lists one or more secrets that the notebook may read during execution (for example, API keys or OAuth tokens referenced from Snowpark or mounted files). Each entry must be a fully qualified secret name. Include this parameter (together with EXTERNAL_ACCESS_INTEGRATIONS) when the notebook performs authenticated outbound access that relies on secrets attached to the notebook service in Snowsight. For setup, UI scheduling, and Python examples, see Using secrets in Notebooks in Workspaces.

Usage notes

Output

Note Before the RETURN_VALUE behavior change, a successful run returned a single column named status or result that contained a success message, such as Statement executed successfully. If your code or tools read that column, update them. A successful run returns one row with one column: Column | Data type | Description RETURN_VALUE | VARCHAR | The value that the notebook passed to notebook.exit(value), or NULL if it didn’t pass one. A Python str is returned as is; any other value is returned as JSON text. RETURN_VALUE is also NULL in the following cases: - The statement returns before the run finishes, for example when the run is executed asynchronously. - The stages that Snowflake uses to cache notebook results in your account aren’t encrypted with SNOWFLAKE_FULL encryption. Returning a value with notebook.exit(value) requires Container Runtime 3.0 or later. Set RUNTIME to a version 3 label, such as 'V3-CPU-PY3.12'. Container Runtime 2.x versions don’t support return values. If the run fails, the command raises an error and returns no row. Decide whether a run succeeded from whether the statement raises an error, not from RETURN_VALUE. To review past runs, use the CODE_BUNDLE_HISTORY table function. For the complete output reference, including Python method entrypoints, see EXECUTE CODE BUNDLE.

Access control requirements

The role executing EXECUTE NOTEBOOK PROJECT must have either OWNERSHIP or USAGE privileges on the notebook project object (NPO). In addition, the executing role must have USAGE on the query warehouse, and USAGE or OWNERSHIP on: - The compute pool. - The database and schema containing the notebook project. - Tasks, external access integrations, and secrets referenced by the command. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

Referenced by