Snowflake Python APIs: Managing Snowflake objects with Python

The Snowflake Python APIs package 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 APIs to manage Snowflake resources by creating, dropping, or altering them, and more. You can use Python to perform tasks you might otherwise perform with Snowflake SQL commands.

To learn more about the API, including its general concepts and design patterns, see Snowflake Python APIs: General concepts.

支持的 Snowflake 资源对象

Note

The API reference documentation reflects the latest version of the Snowflake Python APIs. Note that not all resources in the API currently provide 100% coverage of their equivalent SQL commands, but the Python APIs are under active development and are continuously expanding.

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

Snowflake 中的 Python 生态系统

The Snowflake Python APIs, 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 APIs

您可以使用这套一流的 Python APIs 来定义和管理 Snowflake 工作负载中的核心资源(如表、仓库和任务)。与 Python Connector 不同,这些 APIs 使用原生 Python 与 Snowflake 交互,而无需使用 SQL。

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

按照声明式编程方法,此 API 可以用作 DevOps 工具来管理对资源的更改并自动化 Snowflake 中的代码和基础设施部署。

Snowpark

这套库和代码执行环境可以在 Snowflake 中的数据旁边运行 Python 和其他编程语言。

  • 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.

Snowpark API 支持 Python、Java 和 Scala。

  • 代码执行环境:Snowpark 运行时环境支持容器映像和 Python、Java 和 Scala 代码。
    • 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.

运行时环境也支持 Scala 和 Java。

Snowflake Connector for Python

使用该 SQL 驱动程序连接到 Snowflake,执行 SQL 语句,然后使用 Python 客户端获取结果。

通过 Python Connector,您可以使用 SQL 语句字符串编写与 Snowflake 的所有交互。

Get started with the Snowflake Python APIs

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

  1. Install the library.
  2. Connect to Snowflake.

For tutorials on getting started with the Snowflake Python APIs, see Tutorials: Getting started with the Snowflake Python APIs.

支持的 Python 版本

受支持的 Python 版本包括:

Generally available versions:

  • 3.9 (deprecated)
  • 3.10
  • 3.11
  • 3.12
  • 3.13

开发者指南

GuideDescription
Install the Snowflake Python APIs libraryInstall the Snowflake Python APIs package.
Connect to Snowflake with the Snowflake Python APIsConnect to Snowflake from Python code.
Managing Snowflake accounts and managed accounts with PythonUse the API to create and manage accounts and managed accounts.
Managing Snowflake alerts with PythonUse the API to create and manage alerts.
Managing data loading and unloading resources with PythonUse the API to create and manage data loading and unloading resources, including external volumes, pipes, and stages.
Managing Snowflake databases, schemas, tables, and views with PythonUse the API to create and manage databases, schemas, and tables.
Managing Snowflake dynamic tables with PythonUse the API to create and manage dynamic tables.
Managing Snowflake functions and stored procedures with PythonUse the API to create and manage user-defined functions (UDFs) and stored procedures.
Managing Snowflake integrations with PythonUse the API to create and manage catalog integrations and notification integrations.
Managing Snowflake network policies with PythonUse the API to create and manage network policies.
Managing Snowflake Notebooks with PythonUse the API to create and manage Snowflake Notebooks.
Managing Snowpark Container Services (including service functions) with PythonUse the API to manage components of Snowpark Container Services, including compute pools, image repositories, services, and service functions.
Managing Snowflake streams with PythonUse the API to create and manage streams.
Managing Snowflake tasks and task graphs with PythonUse the API to create, execute, and manage tasks and task graphs.
Managing Snowflake users, roles, and grants with PythonUse the API to create and manage users, roles, and grants.
Managing Snowflake virtual warehouses with PythonUse the API to create and manage virtual warehouses.

引用

Snowflake Python APIs Reference

Snowflake 访问费用

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

API 中的对象要么是本地引用(或 句柄),要么是存储在 Snowflake 上的状态快照。通常,当您处理从 Snowflake 检索到的信息时,您将通过本地的内存引用对象进行处理。

调用方法前,这些引用不与 Snowflake 同步。调用方法时,通常会产生使用 credit 和网络活动费用。相比之下,当您使用内存引用时,例如访问属性时,您的工作是在本地执行的,不会产生任何费用。