Introducing Post Hooks

fal post hooks let you define Python scripts that don't need to write to the data warehouse.

Introducing Post Hooks
Photo by Anne Nygård / Unsplash

Yesterday we introduced fal Python Data Models, which are much like regular dbt models but with Python contents. Users are encouraged to use Python models if their scripts need to write to their data warehouse. Because of this, each Python model requires calling the write_to_model magic function. But what if a user wants to run a script that shouldn’t write to the data warehouse? For this purpose we’re releasing Post Hooks.

Say we want to send a Slack message right after we calculate a dbt model. We can have Python script that gets model status and sends a message:

import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError


client = WebClient(token=SLACK_TOKEN)
message_text = f"Model: {}. Status: {context.current_model.status}."

    response = client.chat_postMessage(
except SlackApiError as e:
    # You will get a SlackApiError if "ok" is False
    assert e.response["error"]

(for more information about making this script work with Slack, check out this blog post)

We turn this script into a post hook in our schema.yml:

 - name: my_target_model

Now, running fal flow run will run after my_target_model.

Overall, post hooks are very similar to the regular fal scripts, with one big exception: you’re not allowed to use write_to_model or write_to_source functions in these scripts.

In the future we will be transitioning away from the old fal "after" scripts and recommend using Python models and post hooks. This way, scripts that have to write to the data warehouse should be formatted as Python models, whereas everything else can be a post hook.

Feedback and comments are always welcome on our Discord server. You can also check out our Github repository, to give us a star or raise an issue.