Snowflake Python API: Managing Snowflake objects with Python

The Snowflake Python API is a unified library that seamlessly connects Python with Snowflake workloads. It is intended to provide comprehensive APIs for interacting with Snowflake resources across data engineering, Snowpark, Snowpark ML, and application workloads using a first-class Python API.

You can use the Snowflake Python API to manage Snowflake resources by creating, deleting, or modifying them, and more. You can use Python to perform tasks you might otherwise perform with Snowflake SQL commands.

The following diagram shows the high-level Snowflake Python API packaging structure:

Diagram showing the high-level Snowflake Python API packaging structure

Python ecosystem in Snowflake

The Snowflake Python API, the Snowpark API for Python, and the Snowflake Connector for Python are interfaces that each have distinct purposes in Snowflake. This section explains their differences and describes the typical use cases for each.

Snowflake Python API

You can use this set of first-class Python APIs to define and manage core resources (such as tables, warehouses, and tasks) across Snowflake workloads. Unlike the Python Connector, these APIs interact with Snowflake using native Python without the need to use SQL.

The Snowflake Python API unifies all Snowflake Python libraries (including connector, core, snowpark, and ml) so that you can simply start with the command pip install snowflake.

Following the declarative programming approach, this API can be used as a DevOps tool to manage changes to your resources and automate code and infrastructure deployment in Snowflake.

Snowpark

This set of libraries and code execution environments can run Python and other programming languages next to your data in Snowflake.

  • Libraries: With the Snowpark API, you can use Snowpark DataFrames in your code to query and transform data entirely within Snowflake. Snowpark applications process your data at scale directly on the Snowflake engine without moving the data to the system where your application code runs.

    The Snowpark API is available in Python, Java, and Scala.

  • Code execution environments: Snowpark runtime environments support container images and Python, Java, and Scala code.

    • You can execute custom Python code through Python user-defined functions (UDFs) or stored procedures for building data pipelines, apps, and more. Python runtime environments have access to a package repository and package manager from Anaconda.

      Runtime environments are also available in Scala and Java.

    • You can run containerized applications directly within Snowflake using Snowpark Container Services.

Snowflake Connector for Python

Use this SQL driver to connect to Snowflake, execute SQL statements, and then get the results using a Python client.

With the Python Connector, you write all of your interactions with Snowflake using SQL statement strings.

Get started with the Snowflake Python API

To get started with the Snowflake Python API, see the instructions in the following topics:

  1. Install the library.

  2. Connect to Snowflake.

With the Snowflake Python API, you can currently manage the following Snowflake objects:

For an introductory tutorial on using the Snowflake Python API, see Quickstart: Getting Started with the Snowflake Python API.

Limitations

The Snowflake Python API is not currently available in the Snowflake Anaconda channel.

Supported versions

The supported versions of Python are:

  • 3.8

  • 3.9

  • 3.10

  • 3.11

Developer guides

Guide

Description

Install the Snowflake Python API library

Install the Snowflake Python API package.

Connect to Snowflake with the Snowflake Python API

Connect to Snowflake from Python code.

Managing Snowflake tasks and task graphs with Python

Use the API to create, execute, and manage tasks and task graphs.

Managing Snowflake databases, schemas, and tables with Python

Use the API to create and manage databases, schemas, and tables.

Managing Snowflake virtual warehouses with Python

Use the API to create and manage virtual warehouses.

Managing Snowpark Container Services with Python

Use the API to manage components of Snowpark Container Services, including compute pools, image repositories, and services.

References

Snowflake Python API Reference

Costs of Snowflake access

To reduce costs—–for both usage credit and network activity—–the Snowflake Python API is designed to communicate with Snowflake only when you call methods designed to synchronize with Snowflake.

Objects in the API are either local references (or handles) or snapshots of state stored on Snowflake. In general, when you process information that was retrieved from Snowflake, you do so through a local, in-memory reference object.

These references do not synchronize with Snowflake until you call a method. When you call a method, you are usually incurring costs in both usage credit and network activity. In contrast, when you work with in-memory references, such as when accessing attributes, your work is performed locally and incurs no such costs.