prefect-snowflake
Welcome!
The prefect-snowflake collection makes it easy to connect to a Snowflake database in your Prefect flows. Check out the examples below to get started!
Getting started
Prerequisites
Install prefect-snowflake
The following command will install a version of prefect-snowflake
compatible with your installed version 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
:
Integrate with Prefect flows
Prefect works with Snowflake by providing dataflow automation for faster, more efficient data pipeline creation, execution, and monitoring.
This results in reduced errors, increased confidence in your data, and ultimately, faster insights.
To set up a table, use the execute
and execute_many
methods. Then, use the fetch_many
method to retrieve data in a stream until there’s no more data.
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.
Be sure to install prefect-snowflake, register the blocks, and create a credentials block to run the examples below!
=== “Sync”
=== “Async”
Access underlying Snowflake connection
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.
Installation
Install prefect-snowflake
with pip
:
Registering blocks
Register blocks in this module to make them available for use.
Saving credentials to a block
Note, to use the load
method on a block, you must already have a block saved through code or saved through the UI.
Below is a walkthrough on saving a SnowflakeCredentials
block through code.
- Head over to https://app.snowflake.com/.
- Login to your Snowflake account, for example: nh12345.us-east-2.snowflake, with your username and password.
- Use those credentials to fill replace the placeholders below.
Then, to create a SnowflakeConnector
block:
- After logging in, click on any worksheet.
- On the left side, select a database and schema.
- On the top right, select a warehouse.
- Create a short script, replacing the placeholders below.
You can now easily load the saved block, which holds your credentials and connection info:
Registering blocks
Register blocks in this module to view and edit them on Prefect Cloud:
A list of available blocks in prefect-snowflake
and their setup instructions can be found here.
Resources
Refer to the prefect-snowflake
SDK documentation to explore all the capabilities of the prefect-snowflake
library.
For further assistance using Snowflake, consult the Snowflake documentation.