Metadata-Version: 2.4
Name: snowflake-snowpark-python
Version: 1.45.0
Summary: Snowflake Snowpark for Python
Home-page: https://www.snowflake.com/
Author: Snowflake, Inc
Author-email: snowflake-python-libraries-dl@snowflake.com
License: Apache License, Version 2.0
Project-URL: Documentation, https://docs.snowflake.com/en/developer-guide/snowpark/python/index.html
Project-URL: Source, https://github.com/snowflakedb/snowpark-python
Project-URL: Issues, https://github.com/snowflakedb/snowpark-python/issues
Project-URL: Changelog, https://github.com/snowflakedb/snowpark-python/blob/main/CHANGELOG.md
Keywords: Snowflake db database cloud analytics warehouse
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Environment :: Other Environment
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: SQL
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: setuptools>=40.6.0
Requires-Dist: wheel
Requires-Dist: snowflake-connector-python<5.0.0,>=3.17.0
Requires-Dist: typing-extensions<5.0.0,>=4.1.0
Requires-Dist: pyyaml
Requires-Dist: cloudpickle!=2.1.0,!=2.2.0,<=3.1.1,>=1.6.0
Requires-Dist: protobuf<6.34,>=3.20
Requires-Dist: python-dateutil
Requires-Dist: tzlocal
Provides-Extra: pandas
Requires-Dist: snowflake-connector-python[pandas]<5.0.0,>=3.17.0; extra == "pandas"
Provides-Extra: modin
Requires-Dist: snowflake-connector-python[pandas]<5.0.0,>=3.17.0; extra == "modin"
Requires-Dist: modin<0.38.0,>=0.36.0; extra == "modin"
Requires-Dist: pandas<=2.3.1; extra == "modin"
Requires-Dist: tqdm; extra == "modin"
Requires-Dist: ipywidgets; extra == "modin"
Provides-Extra: secure-local-storage
Requires-Dist: snowflake-connector-python[secure-local-storage]<5.0.0,>=3.17.0; extra == "secure-local-storage"
Provides-Extra: development
Requires-Dist: pytest<8.0.0; extra == "development"
Requires-Dist: pytest-cov; extra == "development"
Requires-Dist: wrapt; extra == "development"
Requires-Dist: coverage; extra == "development"
Requires-Dist: sphinx==5.0.2; extra == "development"
Requires-Dist: cachetools; extra == "development"
Requires-Dist: pytest-timeout; extra == "development"
Requires-Dist: pytest-xdist; extra == "development"
Requires-Dist: openpyxl; extra == "development"
Requires-Dist: matplotlib; extra == "development"
Requires-Dist: pre-commit; extra == "development"
Requires-Dist: graphviz; extra == "development"
Requires-Dist: pytest-assume; extra == "development"
Requires-Dist: decorator; extra == "development"
Requires-Dist: tox; extra == "development"
Requires-Dist: snowflake.core<2,>=1.0.0; extra == "development"
Requires-Dist: psutil; extra == "development"
Requires-Dist: lxml; extra == "development"
Provides-Extra: modin-development
Requires-Dist: snowflake-connector-python[pandas]<5.0.0,>=3.17.0; extra == "modin-development"
Requires-Dist: modin<0.38.0,>=0.36.0; extra == "modin-development"
Requires-Dist: pandas<=2.3.1; extra == "modin-development"
Requires-Dist: tqdm; extra == "modin-development"
Requires-Dist: ipywidgets; extra == "modin-development"
Requires-Dist: pytest<8.0.0; extra == "modin-development"
Requires-Dist: pytest-cov; extra == "modin-development"
Requires-Dist: wrapt; extra == "modin-development"
Requires-Dist: coverage; extra == "modin-development"
Requires-Dist: sphinx==5.0.2; extra == "modin-development"
Requires-Dist: cachetools; extra == "modin-development"
Requires-Dist: pytest-timeout; extra == "modin-development"
Requires-Dist: pytest-xdist; extra == "modin-development"
Requires-Dist: openpyxl; extra == "modin-development"
Requires-Dist: matplotlib; extra == "modin-development"
Requires-Dist: pre-commit; extra == "modin-development"
Requires-Dist: graphviz; extra == "modin-development"
Requires-Dist: pytest-assume; extra == "modin-development"
Requires-Dist: decorator; extra == "modin-development"
Requires-Dist: tox; extra == "modin-development"
Requires-Dist: snowflake.core<2,>=1.0.0; extra == "modin-development"
Requires-Dist: psutil; extra == "modin-development"
Requires-Dist: lxml; extra == "modin-development"
Requires-Dist: scipy<=1.16.0; extra == "modin-development"
Requires-Dist: statsmodels; extra == "modin-development"
Requires-Dist: scikit-learn; extra == "modin-development"
Requires-Dist: plotly<6.0.0; extra == "modin-development"
Requires-Dist: snowflake-ml-python>=1.8.0; python_version < "3.12" and extra == "modin-development"
Requires-Dist: s3fs; extra == "modin-development"
Requires-Dist: ray; extra == "modin-development"
Provides-Extra: localtest
Requires-Dist: pandas; extra == "localtest"
Requires-Dist: requests; extra == "localtest"
Provides-Extra: opentelemetry
Requires-Dist: opentelemetry-api<2.0.0,>=1.0.0; extra == "opentelemetry"
Requires-Dist: opentelemetry-sdk<2.0.0,>=1.0.0; extra == "opentelemetry"
Requires-Dist: opentelemetry-exporter-otlp<2.0.0,>=1.0.0; extra == "opentelemetry"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Snowflake Snowpark Python and Snowpark pandas APIs

[![Build and Test](https://github.com/snowflakedb/snowpark-python/actions/workflows/precommit.yml/badge.svg)](https://github.com/snowflakedb/snowpark-python/actions/workflows/precommit.yml)
[![codecov](https://codecov.io/gh/snowflakedb/snowpark-python/branch/main/graph/badge.svg)](https://codecov.io/gh/snowflakedb/snowpark-python)
[![PyPi](https://img.shields.io/pypi/v/snowflake-snowpark-python.svg)](https://pypi.org/project/snowflake-snowpark-python/)
[![License Apache-2.0](https://img.shields.io/:license-Apache%202-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)
[![Codestyle Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

The Snowpark library provides intuitive APIs for querying and processing data in a data pipeline.
Using this library, you can build applications that process data in Snowflake without having to move data to the system where your application code runs.

[Source code][source code] | [Snowpark Python developer guide][Snowpark Python developer guide] | [Snowpark Python API reference][Snowpark Python api references] | [Snowpark pandas developer guide][Snowpark pandas developer guide] | [Snowpark pandas API reference][Snowpark pandas api references] | [Product documentation][snowpark] | [Samples][samples]

## Getting started

### Have your Snowflake account ready
If you don't have a Snowflake account yet, you can [sign up for a 30-day free trial account][sign up trial].

### Create a Python virtual environment
You can use [miniconda][miniconda], [anaconda][anaconda], or [virtualenv][virtualenv]
to create a Python 3.9, 3.10, 3.11, 3.12 or 3.13 virtual environment.

For Snowpark pandas, only Python 3.9, 3.10, or 3.11 is supported.

To have the best experience when using it with UDFs, [creating a local conda environment with the Snowflake channel][use snowflake channel] is recommended.

### Install the library to the Python virtual environment
```bash
pip install snowflake-snowpark-python
```
To use the [Snowpark pandas API][Snowpark pandas developer guide], you can optionally install the following, which installs [modin][modin] in the same environment. The Snowpark pandas API provides a familiar interface for pandas users to query and process data directly in Snowflake.
```bash
pip install "snowflake-snowpark-python[modin]"
```

### Create a session and use the Snowpark Python API
```python
from snowflake.snowpark import Session

connection_parameters = {
  "account": "<your snowflake account>",
  "user": "<your snowflake user>",
  "password": "<your snowflake password>",
  "role": "<snowflake user role>",
  "warehouse": "<snowflake warehouse>",
  "database": "<snowflake database>",
  "schema": "<snowflake schema>"
}

session = Session.builder.configs(connection_parameters).create()
# Create a Snowpark dataframe from input data
df = session.create_dataframe([[1, 2], [3, 4]], schema=["a", "b"]) 
df = df.filter(df.a > 1)
result = df.collect()
df.show()

# -------------
# |"A"  |"B"  |
# -------------
# |3    |4    |
# -------------
```

### Create a session and use the Snowpark pandas API
```python
import modin.pandas as pd
import snowflake.snowpark.modin.plugin
from snowflake.snowpark import Session

CONNECTION_PARAMETERS = {
    'account': '<myaccount>',
    'user': '<myuser>',
    'password': '<mypassword>',
    'role': '<myrole>',
    'database': '<mydatabase>',
    'schema': '<myschema>',
    'warehouse': '<mywarehouse>',
}
session = Session.builder.configs(CONNECTION_PARAMETERS).create()

# Create a Snowpark pandas dataframe from input data
df = pd.DataFrame([['a', 2.0, 1],['b', 4.0, 2],['c', 6.0, None]], columns=["COL_STR", "COL_FLOAT", "COL_INT"])
df
#   COL_STR  COL_FLOAT  COL_INT
# 0       a        2.0      1.0
# 1       b        4.0      2.0
# 2       c        6.0      NaN

df.shape
# (3, 3)

df.head(2)
#   COL_STR  COL_FLOAT  COL_INT
# 0       a        2.0        1
# 1       b        4.0        2

df.dropna(subset=["COL_INT"], inplace=True)

df
#   COL_STR  COL_FLOAT  COL_INT
# 0       a        2.0        1
# 1       b        4.0        2

df.shape
# (2, 3)

df.head(2)
#   COL_STR  COL_FLOAT  COL_INT
# 0       a        2.0        1
# 1       b        4.0        2

# Save the result back to Snowflake with a row_pos column.
df.reset_index(drop=True).to_snowflake('pandas_test2', index=True, index_label=['row_pos'])
```

## Samples
The [Snowpark Python developer guide][Snowpark Python developer guide], [Snowpark Python API references][Snowpark Python api references], [Snowpark pandas developer guide][Snowpark pandas developer guide], and [Snowpark pandas api references][Snowpark pandas api references] have basic sample code.
[Snowflake-Labs][snowflake lab sample code] has more curated demos.

## Logging
Configure logging level for `snowflake.snowpark` for Snowpark Python API logs.
Snowpark uses the [Snowflake Python Connector][python connector].
So you may also want to configure the logging level for `snowflake.connector` when the error is in the Python Connector.
For instance,
```python
import logging
for logger_name in ('snowflake.snowpark', 'snowflake.connector'):
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s'))
    logger.addHandler(ch)
```

## Reading and writing to pandas DataFrame

Snowpark Python API supports reading from and writing to a pandas DataFrame via the [to_pandas][to_pandas] and [write_pandas][write_pandas] commands. 

To use these operations, ensure that pandas is installed in the same environment. You can install pandas alongside Snowpark Python by executing the following command:
```bash
pip install "snowflake-snowpark-python[pandas]"
```
Once pandas is installed, you can convert between a Snowpark DataFrame and pandas DataFrame as follows: 
```python
df = session.create_dataframe([[1, 2], [3, 4]], schema=["a", "b"])
# Convert Snowpark DataFrame to pandas DataFrame
pandas_df = df.to_pandas() 
# Write pandas DataFrame to a Snowflake table and return Snowpark DataFrame
snowpark_df = session.write_pandas(pandas_df, "new_table", auto_create_table=True)
```

Snowpark pandas API also supports writing to pandas: 
```python
import modin.pandas as pd
df = pd.DataFrame([[1, 2], [3, 4]], columns=["a", "b"])
# Convert Snowpark pandas DataFrame to pandas DataFrame
pandas_df = df.to_pandas() 
```

Note that the above Snowpark pandas commands will work if Snowpark is installed with the `[modin]` option, the additional `[pandas]` installation is not required.

## Verifying Package Signatures

To ensure the authenticity and integrity of the Python package, follow the steps below to verify the package signature using `cosign`.

**Steps to verify the signature:**
- Install cosign:
  - This example is using golang installation: [installing-cosign-with-go](https://edu.chainguard.dev/open-source/sigstore/cosign/how-to-install-cosign/#installing-cosign-with-go)
- Download the file from the repository like pypi:
  - https://pypi.org/project/snowflake-snowpark-python/#files
- Download the signature files from the release tag, replace the version number with the version you are verifying:
  - https://github.com/snowflakedb/snowpark-python/releases/tag/v1.22.1
- Verify signature:
  ````bash
  # replace the version number with the version you are verifying
  ./cosign verify-blob snowflake_snowpark_python-1.22.1-py3-none-any.whl  \
  --certificate snowflake_snowpark_python-1.22.1-py3-none-any.whl.crt \
  --certificate-identity https://github.com/snowflakedb/snowpark-python/.github/workflows/python-publish.yml@refs/tags/v1.22.1 \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  --signature snowflake_snowpark_python-1.22.1-py3-none-any.whl.sig
  Verified OK
  ````

## Contributing
Please refer to [CONTRIBUTING.md][contributing].

[add other sample code repo links]: # (Developer advocacy is open-sourcing a repo that has excellent sample code. The link will be added here.)

[Snowpark Python developer guide]: https://docs.snowflake.com/en/developer-guide/snowpark/python/index.html
[Snowpark Python api references]: https://docs.snowflake.com/en/developer-guide/snowpark/reference/python/index.html
[Snowpark pandas developer guide]: https://docs.snowflake.com/developer-guide/snowpark/python/snowpark-pandas
[Snowpark pandas api references]: https://docs.snowflake.com/developer-guide/snowpark/reference/python/latest/modin/index
[snowpark]: https://www.snowflake.com/snowpark
[sign up trial]: https://signup.snowflake.com
[source code]: https://github.com/snowflakedb/snowpark-python
[miniconda]: https://docs.conda.io/en/latest/miniconda.html
[anaconda]: https://www.anaconda.com/
[virtualenv]: https://docs.python.org/3/tutorial/venv.html
[config pycharm interpreter]: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html
[python connector]: https://pypi.org/project/snowflake-connector-python/
[use snowflake channel]: https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-packages.html#local-development-and-testing
[snowflake lab sample code]: https://github.com/Snowflake-Labs/snowpark-python-demos
[samples]: https://github.com/snowflakedb/snowpark-python/blob/main/README.md#samples
[contributing]: https://github.com/snowflakedb/snowpark-python/blob/main/CONTRIBUTING.md
[to_pandas]: https://docs.snowflake.com/developer-guide/snowpark/reference/python/latest/snowpark/api/snowflake.snowpark.DataFrame.to_pandas
[write_pandas]: https://docs.snowflake.com/developer-guide/snowpark/reference/python/latest/snowpark/api/snowflake.snowpark.Session.write_pandas
[modin]: https://github.com/modin-project/modin
