Kaleb King
03/15/2025, 3:46 AMfrom prefect_snowflake import SnowflakeCredentials
credentials = SnowflakeCredentials.load(prefect_block_name)
connection = credentials.get_client()
Marvin
03/15/2025, 3:47 AMpython
from prefect import flow, task
from prefect_snowflake import SnowflakeCredentials
@task
def create_connection(prefect_block_name):
credentials = SnowflakeCredentials.load(prefect_block_name)
return credentials
@task
def use_connection(credentials):
connection = credentials.get_client()
# Use the connection here
# Make sure to close the connection if needed
connection.close()
@flow
def my_flow(prefect_block_name):
credentials = create_connection(prefect_block_name)
use_connection(credentials)
my_flow("your_prefect_block_name")
This method leverages the ability to pass serializable data (like credentials) between tasks. You can read more about handling credentials and connections in Prefect here.