> ## Content Index
> Fetch the complete content index at: https://www.daanalytics.nl/llms.txt
> Use this file to discover other available public pages before exploring further.

# Using Python in Snowflake Worksheets
- URL: https://www.daanalytics.nl/introducing-snowflake-worksheets-for-python/
- Published: 2023-04-05T12:36:15.000Z
- Updated: 2026-08-28T07:33:21.000Z
- Author: Daan Bakboord
- Tags: Python & Streamlit, Snowflake, Faker, Python, Snowsight, Worksheets

Recently Snowflake made working with Python from within Snowflake a little bit better. 'Snowflake Worksheets for Python' is in Public Preview, available for use for everybody. Time to find out how it works.

### Generate Faker Data

I am planning a series of blogpost regarding Snowflake Data Governance in combination with [Alation](https://alation.com/?ref=daanalytics.nl). Therefore I need some demo data. Recently I saw a [blogpost](https://medium.com/snowflake/generating-sample-data-using-the-faker-library-with-snowpark-e60d4cd3b14e?ref=daanalytics.nl) of my fellow Snowflake Data Superhero; Maja Ferle about generating Sample Data using the *faker* Library within Snowpark. I took that blogpost as a starting point to generate some fake Customer Data using Snowflake Worksheets for Python.

#### Enable Anaconda Python Packages

To be able to use the Snowflake Worksheets for Python feature, you first need to [review and accept](https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-packages?ref=daanalytics.nl#label-python-udfs-anaconda-terms) the Anaconda Terms of Service in Snowsight. Therefor you need to follow the next steps:

1. Select the ORGADMIN-role
2. Go to Admin, Billing & Terms
3. Enable Anaconda Python packages
4. Acknowledge & Continue

![Enable Anaconda Python Packages](https://www.daanalytics.nl/content/images/2023/04/Enable-Anaconda-Python-Packages-1024x576-2.png)

#### Packages available in Anaconda

First you have to make sure that the required packages are available in Anaconda, by either checking the [documentation](https://repo.anaconda.com/pkgs/snowflake/?ref=daanalytics.nl) or executing the following query:

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/214029b0afd8253ecd2d585e6c4135ce?ref=daanalytics.nl)

If you want to select specific packages and their versions, execute the following query. In this example we are looking for; 'faker' and 'pandas'.

[Bekijk code op GitHub Gist](https://gist.github.com/daanalytics/bb39ab8664350bbcaf65fd44ddc3c757?ref=daanalytics.nl)

There might be a need to include packages that are not available from Anaconda. According to the [documentation](https://docs.snowflake.com/en/developer-guide/snowpark/python/python-worksheets?ref=daanalytics.nl#label-snowsight-py-worksheets-add-py-file), you can add a Python File from a Stage to a Worksheet.

#### Preparing Python Worksheet

Before you start developing in the Snowflake Worksheets for Python, the worksheet needs to be prepared.

1. Select the Python Worksheet
2. Select a database
3. Select a warehouse
4. Define how yo want to run the worksheet
  - set the 'Handler' (the function to be called when executing the worksheet)
  - set the 'Return type' (the type of result returned by the 'Handler')
5. Select the required packages
  - first select the package, then import the package in the worksheet
6. Try to run the sample code to make sure things work.

![Preparing Snowflake for Python Worksheet](https://www.daanalytics.nl/content/images/2023/04/Prepare-Python-Worksheets-1024x576-2.png)

#### Developing in Snowflake Worksheets for Python

When starting a new Python Worksheet, the sheet is filled with some sample code. This code can easily be changed according to your own needs. The code I needed to generate a simple Customer tabel is on [GitHub](https://github.com/daanalytics/Snowflake/blob/master/python/snowpark/genCustomerFakerData.py?ref=daanalytics.nl).

1. Add the code to the Python Worksheet and run the code
2. View the results
3. In this case the script (re-)creates and loads a table
  - view the results by selecting from the newly created table

![Developing in Snowflake Worksheets for Python](https://www.daanalytics.nl/content/images/2023/04/Developing-in-Snowflake-Worksheets-for-Python-1024x576-2.png)

**Note:** If you run code via the Snowsight UI there will be added some additional execution time +/- 10 to 20 secs extra as it executes as a temporary Stored Procedure each run. If you register it as a Permanent Stored Procedure it will eliminate this extra execution time.

#### Deploy the code as a Stored Procedure

With a simple click of a button your Python script can be deployed as a Permanent Stored Procedure.

1. Click 'Deploy'
2. Name the Stored Procedure
  - Name
  - Description
  - Overwrite existing (Y/N)
3. Call procedure
4. Verify results in table

![Deploy the Python code as a Stored Procedure](https://www.daanalytics.nl/content/images/2023/04/Deploy-Python-Code-1024x576-2.png)

### Closing Statements

Python Worksheets for Snowflake are now in Public Preview which means it's available to everyone. A native Python Code Editor in SnowSight including IntelliSense with auto-complete, Sowpark and third-party library support both via either Anaconda or manual upload of custom packages.

Deploying the Python scripts as Python Stored Procedures is easy and makes it possible to automatically schedule them via Snowflake Tasks.

More details in the Snowflake [documentation](https://lnkd.in/eQAGcJ7F?ref=daanalytics.nl); 'Writing Snowpark Code in Python Worksheets'.

Till next time.

[Daan Bakboord – DaAnalytics](https://www.linkedin.com/in/daanbakboord?ref=daanalytics.nl)