Upload an existing Python package¶
Snowflake CLI allows you to add existing Python packages to Snowpark imports using the snow snowpark package commands. You can use already implemented packages, such as those from PyPi, in your functions and procedures.
To add a Python package to Snowpark imports, do the following:
Check whether a package is already available¶
To check whether a package is not already available use the snow snowpark package lookup command.
The following example illustrates looking up a package that is already available on the Snowflake Anaconda channel:
If a package is not available on the Snowflake Anaconda channel, you can get a message similar to the following:
For more information, see the snowpark package lookup command.
Download a package and create a Snowflake artifact¶
To download a package and create a Snowflake artifact to upload use the snow snowpark package create command.
where:
<name>can be any requirement specifier supported bypip, such as a package name, an URL for a package, or a local file path.
Additional options:
--allow-shared-libraries: Allows shared (.so/.dll) libraries, when using packages installed throughpip.--ignore-anaconda: Does not lookup packages on Snowflake Anaconda channel.--index-url: Specifies the base URL of the Python Package Index to use for package lookup. This URL should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.--skip-version-check: Skips comparing versions of dependencies between requirements and Anaconda.
The following examples illustrate some different situations for creating Snowflake artifacts:
Example: create a package using the --ignore-anaconda option
Example: create a package already available in the Snowflake Anaconda channel
Example: create a package with Anaconda dependencies¶
This example creates a Python package as a zip file that can be uploaded to a stage and later imported by a Snowpark Python app. Dependencies for “july” package are found on the Anaconda channel, so they were excluded from the .zip file. The command displays the packages you would need to include in requirements.txt of your Snowpark project.
Example: create a package using the --ignore-anaconda option¶
This example creates the july.zip package that you can use in your Snowpark project without needing to add any dependencies to the requirements.txt file. The error messages indicate that some packages contain shared libraries, which might not work, such as when creating a package using Windows.
Example: create a package already available in the Snowflake Anaconda channel¶
This example fails to create the package because it already exists. You can still forcibly create the package by using the --ignore-anaconda option.
For more information about creating a package, see the snowpark package create command.
Upload the package to a Snowflake stage¶
To upload your package, use the snow snowpark package upload command.
This command uploads a Python package zip file to a Snowflake stage so it can be referenced in the imports of a procedure or function.
Use the package in Snowpark procedures and functions¶
To use the package in procedures or functions, add it to the imports parameter of Snowpark definition section in snowflake.yml.
Then import your package in the function handler.