Module Contents



Executes an SQL statement in Snowflake and sends the results to Slack. The results of the query are

class airflow.providers.snowflake.transfers.snowflake_to_slack.SnowflakeToSlackOperator(*, sql, slack_message, snowflake_conn_id='snowflake_default', slack_conn_id='slack_default', results_df_name='results_df', parameters=None, warehouse=None, database=None, schema=None, role=None, slack_token=None, **kwargs)[source]

Bases: airflow.models.BaseOperator

Executes an SQL statement in Snowflake and sends the results to Slack. The results of the query are rendered into the 'slack_message' parameter as a Pandas dataframe using a JINJA variable called '{{ results_df }}'. The 'results_df' variable name can be changed by specifying a different 'results_df_name' parameter. The Tabulate library is added to the JINJA environment as a filter to allow the dataframe to be rendered nicely. For example, set 'slack_message' to {{ results_df | tabulate(tablefmt="pretty", headers="keys") }} to send the results to Slack as an ascii rendered table.

See also

For more information on how to use this operator, take a look at the guide: SnowflakeToSlackOperator

  • sql (str) -- The SQL statement to execute on Snowflake (templated)

  • slack_message (str) -- The templated Slack message to send with the data returned from Snowflake. You can use the default JINJA variable {{ results_df }} to access the pandas dataframe containing the SQL results

  • snowflake_conn_id (str) -- Reference to Snowflake connection id

  • slack_conn_id (str) -- The connection id for Slack

  • results_df_name (str) -- The name of the JINJA template's dataframe variable, default is 'results_df'

  • parameters (Optional[Union[Iterable, Mapping]]) -- The parameters to pass to the SQL query

  • warehouse (Optional[str]) -- The Snowflake virtual warehouse to use to run the SQL query

  • database (Optional[str]) -- The Snowflake database to use for the SQL query

  • schema (Optional[str]) -- The schema to run the SQL against in Snowflake

  • role (Optional[str]) -- The role to use when connecting to Snowflake

  • slack_token (Optional[str]) -- The token to use to authenticate to Slack. If this is not provided, the 'webhook_token' attribute needs to be specified in the 'Extra' JSON field against the slack_conn_id

template_fields :Sequence[str] = ['sql', 'slack_message'][source]
template_ext :Sequence[str] = ['.sql', '.jinja', '.j2'][source]
times_rendered = 0[source]
render_template_fields(self, context, jinja_env=None)[source]

Template all attributes listed in template_fields.

This mutates the attributes in-place and is irreversible.

  • context -- Dict with values to apply on content

  • jinja_env -- Jinja environment

execute(self, context)[source]

This is the main method to derive when creating an operator. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

Was this entry helpful?