Skip to main content
The prefect-snowflake integration makes it easy to connect to Snowflake in your Prefect flows. You can run queries both synchronously and asynchronously as Prefect flows and tasks.

Getting started

Prerequisites

Installation

Install prefect-snowflake as a dependency of Prefect. If you don’t already have Prefect installed, it will install the newest version of prefect as well.
Upgrade to the latest versions of prefect and prefect-snowflake:

Blocks setup

The prefect-snowflake integration has two blocks: one for storing credentials and one for storing connection information. Register blocks in this module to view and edit them on Prefect Cloud:

Create the credentials block

Below is a walkthrough on saving a SnowflakeCredentials block through code. Log into your Snowflake account to find your credentials. The example below uses a user and password combination, but refer to the SDK documentation for a full list of authentication and connection options.

Create the connection block

Then, to create a SnowflakeConnector block:
  1. After logging in, click on any worksheet.
  2. On the left side, select a database and schema.
  3. On the top right, select a warehouse.
  4. Create a short script, replacing the placeholders below.
You can now easily load the saved block, which holds your credentials and connection info:

Examples

To set up a table, use the execute and execute_many methods. Then, use the fetch_all method. If the results are too large to fit into memory, use the fetch_many method to retrieve data in chunks. By using the SnowflakeConnector as a context manager, you can make sure that the Snowflake connection and cursors are closed properly after you’re done with them.
If the native methods of the block don’t meet your requirements, don’t worry. You have the option to access the underlying Snowflake connection and utilize its built-in methods as well.

Resources

Refer to the prefect-snowflake SDK documentation to explore other capabilities of the prefect-snowflake library, such as async methods. For further assistance using Snowflake, consult the Snowflake documentation or the Snowflake Python Connector documentation.