You are viewing documentation about an older version (1.12.1). View latest version

snowflake.snowpark.stored_procedure.StoredProcedureRegistration.register_from_file

StoredProcedureRegistration.register_from_file(file_path: str, func_name: str, return_type: Optional[DataType] = None, input_types: Optional[List[DataType]] = None, name: Optional[Union[str, Iterable[str]]] = None, is_permanent: bool = False, stage_location: Optional[str] = None, imports: Optional[List[Union[str, Tuple[str, str]]]] = None, packages: Optional[List[Union[str, module]]] = None, replace: bool = False, if_not_exists: bool = False, parallel: int = 4, execute_as: Literal['caller', 'owner'] = 'owner', strict: bool = False, external_access_integrations: Optional[List[str]] = None, secrets: Optional[Dict[str, str]] = None, *, statement_params: Optional[Dict[str, str]] = None, source_code_display: bool = True, skip_upload_on_content_match: bool = False) StoredProcedure[source]

Registers a Python function as a Snowflake Python stored procedure from a Python or zip file, and returns the stored procedure. Apart from file_path and func_name, the input arguments of this method are the same as register(). See examples in StoredProcedureRegistration.

Parameters:
  • file_path – The path of a local file or a remote file in the stage. See more details on path argument of session.add_import(). Note that unlike path argument of session.add_import(), here the file can only be a Python file or a compressed file (e.g., .zip file) containing Python modules.

  • func_name – The Python function name in the file that will be created as a stored procedure.

  • return_type – A DataType representing the return data type of the stored procedure. Optional if type hints are provided.

  • input_types – A list of DataType representing the input data types of the stored procedure. Optional if type hints are provided.

  • name – A string or list of strings that specify the name or fully-qualified object identifier (database name, schema name, and function name) for the stored procedure in Snowflake, which allows you to call this stored procedure in a SQL command or via call(). If it is not provided, a name will be automatically generated for the stored procedure. A name must be specified when is_permanent is True.

  • is_permanent – Whether to create a permanent stored procedure. The default is False. If it is True, a valid stage_location must be provided.

  • stage_location – The stage location where the Python file for the stored procedure and its dependencies should be uploaded. The stage location must be specified when is_permanent is True, and it will be ignored when is_permanent is False. It can be any stage other than temporary stages and external stages.

  • imports – A list of imports that only apply to this stored procedure. You can use a string to represent a file path (similar to the path argument in add_import()) in this list, or a tuple of two strings to represent a file path and an import path (similar to the import_path argument in add_import()). These stored procedure-level imports will override the session-level imports added by add_import().

  • packages – A list of packages that only apply to this stored procedure. These stored procedure-level packages will override the session-level packages added by add_packages() and add_requirements().

  • replace – Whether to replace a stored procedure that already was registered. The default is False. If it is False, attempting to register a stored procedure with a name that already exists results in a SnowparkSQLException exception being thrown. If it is True, an existing stored procedure with the same name is overwritten.

  • if_not_exists – Whether to skip creation of a stored procedure the same procedure is already registered. The default is False. if_not_exists and replace are mutually exclusive and a ValueError is raised when both are set. If it is True and a stored procedure is already registered, the registration is skipped.

  • parallel – The number of threads to use for uploading stored procedure files with the PUT command. The default value is 4 and supported values are from 1 to 99. Increasing the number of threads can improve performance when uploading large stored procedure files.

  • execute_as – What permissions should the procedure have while executing. This supports caller, or owner for now.

  • strict – Whether the created stored procedure is strict. A strict stored procedure will not invoke the stored procedure if any input is null. Instead, a null value will always be returned. Note that the stored procedure might still return null for non-null inputs.

  • statement_params – Dictionary of statement level parameters to be set while executing this action.

  • source_code_display – Display the source code of the stored procedure func as comments in the generated script. The source code is dynamically generated therefore it may not be identical to how the func is originally defined. The default is True. If it is False, source code will not be generated or displayed.

  • skip_upload_on_content_match – When set to True and a version of source file already exists on stage, the given source file will be uploaded to stage only if the contents of the current file differ from the remote file on stage. Defaults to False.

  • external_access_integrations – The names of one or more external access integrations. Each integration you specify allows access to the external network locations and secrets the integration specifies.

  • secrets – The key-value pairs of string types of secrets used to authenticate the external network location. The secrets can be accessed from handler code. The secrets specified as values must also be specified in the external access integration and the keys are strings used to retrieve the secrets using secret API.

Note::

The type hints can still be extracted from the source Python file if they are provided, but currently are not working for a zip file. Therefore, you have to provide return_type and input_types when path points to a zip file.

See also