dbt Python model#

To incorporate Python in our workflow, we will use Fal. For more information on Fal, please refer to the Fal documentation. The latest version of dbt support python models on its own, however these are models running directly inside vendors: e.g. Snowpark or Databricks. Due to limits of this workshops, we are running python model locally and for this purpose Fal AI is perfect choice.

Setup all things needed#

  1. fal python models:

    1. Create a new folder called ml in the models/marts folder. This is where we will store our ML models.

    2. Inside the ml folder, create a new file called _ml.yml with model and source definition.

    3. Also add the dbt model itself customer_registration_prediction.sql with simple query inside.

  2. fal python scripts:

    1. Navigate to scripts folder in dbt_demo folder and add prediction script called customer_registration_prediction.py in it.

    2. Append fal var setting into dbt_project.yml so fal-ai knows where to find them.

  3. fal python models: Ready to run it

    1. First run the selected new dbt models dbt run --select marts.ml.*

    2. Take a look at the created table dbt_ml.customer_registration_prediction

    3. Then run the python script itself fal run

    4. Now you can take a look at the table again.

  4. [BONUS] Add staging ml folder and incorporate all the way up into customers table so you manager can see it in his dashboard!