Create a Snowpark project definition

The snowflake.yml file contains the functions and procedures declarations for a Snowpark project.

Note

Currently, the Snowpark project definition file must be named snowflake.yml.

The following snippet shows a sample Snowpark project definition file: with two functions and two procedures. The hello_function function uses external capabilities of Snowpark.

definition_version: '2'

mixins:
  snowpark_shared:
    artifacts:
      - dest: my_snowpark_project
        src: app/
    stage: dev_deployment

entities:

  hello_function:
    type: function
    identifier:
      name: hello_function
    handler: functions.hello_function
    signature:
      - name: name
        type: string
    returns: string
    external_access_integrations:
      - my_external_access
    secrets:
        cred: my_cred_name
    meta:
      use_mixins:
        - snowpark_shared

  hello_procedure:
    type: procedure
    identifier:
      name: hello_procedure
    handler: procedures.hello_procedure
    signature:
      - name: name
        type: string
    returns: string
    meta:
      use_mixins:
        - snowpark_shared

  test_procedure:
    type: procedure
    identifier:
      name: test_procedure
    handler: procedures.test_procedure
    signature: ''
    returns: string
    meta:
      use_mixins:
        - snowpark_shared
Copy

Caution

Files inside a project directory are processed by Snowflake CLI and could be uploaded to Snowflake when executing other snow snowpark commands. You should use caution when putting any sensitive information inside files in a project directory.

Function and procedure object properties

The following table describes the properties used by functions and procedures.

Function and procedure object properties

Property

Definition

identifier

optional, string

Optional Snowflake identifier for the entity. The value can have the following forms:

  • String identifier text

    identifer: my-snowpark-id
    
    Copy

    Both unquoted and quoted identifiers are supported. To use quoted identifiers, include the surrounding quotes in the YAML value (e.g. ’”My Snowpark Function”’).

  • Object

    identifer:
      name: my-snowpark-id
      schema: my-schema # optional
      database: my-db # optional
    
    Copy

    Note

    An error occurs if you specify a schema or database and use a fully-qualified name in the name property (such as mydb.schema1.my-app).

type

optional, string

Must be one of: function or procedure.

artifacts

required, string sequence

List of required resources.

handler

required, string

Function’s or procedure’s implementation of the object inside module defined in snowpark.src. For example functions.hello_function refers to function hello_function from file <src>/functions.py.

returns

required, string

SQL type of the result. Check the list of available types.

signature

required, sequence

The signature parameter describes consecutive arguments passed to the object. Each should specify its name and type, for example:

signature:
  - name: "first_argument"
    type: int
  - name: "second_argument"
    default: "default value"
    type: string
Copy

If a function or procedure takes no arguments, set this value to an empty string (signature: "").

Check the SQL Type column of available types. To learn more about the syntax of named and optional arguments, see Calling a UDF that has optional arguments.

runtime

optional, string

Python version to use when executing the procedure or function. Default: “3.8”.

external_access_integrations

optional, string sequence

Names of external access integrations needed for this procedure’s handler code to access external networks. See CREATE PROCEDURE for more details.

secrets

optional, dictionary

Assigns the names of secrets to variables so that you can use the variables to reference the secrets when retrieving information from secrets in handler code. See CREATE PROCEDURE for more details.

imports

optional, string sequence

Stage and path to previously uploaded files you want to import. See CREATE PROCEDURE for more details.

execute_as_caller

optional, bool

Available only for procedures. Determine whether the procedure is executed with the privileges of the owner (you) or with the privileges of the caller. Default: False (owner’s privileges).