Custom Packages in Streamlit-in-Snowflake

Hi folks,

I have one query, and I am not finding any solution yet.

If Streamlit in Snowflake doesn’t support a Python package, then is there any possible way that I can use that package in Streamlit on Snowflake?

Thanking you
ss

Hello @ss_mohanty,

To my knowledge, Snowflake’s support for external Python packages in the Streamlit integration may be limited compared to running Streamlit in a standalone environment. This limitation is due to the security, compatibility, and performance considerations within Snowflake’s managed service environment.

Here are some approaches to consider:

  1. Use Alternative Supported Packages: Look for alternative packages that are supported by Snowflake and provide similar functionality (might require some research and flexibility in how you implement your solution)
  2. Custom Python UDFs and Stored Procedures: If the functionality you require from the unsupported package can be encapsulated within Python code, you might be able to implement it as a User-Defined Function (UDF) or a stored procedure in Snowflake (this might not be feasible for all types of package functionalities)
  3. External Processing: For complex scenarios where none of the above solutions are viable, consider processing the data outside of Snowflake using the required package, and then moving the processed data back into Snowflake.

Hope this helps!

Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer

P.S. Lets connect on LinkedIn!

➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ 100+ FREE Power BI Themes: Download Now

3 Likes

I have deployed a streamlit native app in snowflake. The issue I am currently facing is, I need third party package which is not available in snowflake.

Approach:
I have .zip the external package and upload to the application stage of native app in streamlit and create a user defined function to use the external package in the streamlit in snowflake.

import snowflake.snowpark.functions as F

# external package path 
snowflake_session.add_import('@"TEST_DB"."CODE"."SD"/polars.zip')


@F.udf(func="addpolars", packages=["polars"], replace=True, return_type=str)
def testing():
    
    import polars
    return "hello"

testing()

user defined function

CREATE OR REPLACE FUNCTION addpolars() 
RETURNS STRING 
LANGUAGE PYTHON 
RUNTIME_VERSION = '3.8' 
PACKAGES = ('snowflake-snowpark-python') 
IMPORTS = ('@SD/polars.zip' ) 
HANDLER = 'add_polar' 
as 
$$ 
def add_polar(): 

  import polars 

$$;

could you please help me to fix the issue ?