Skip to main content

Welcome to dbt-postgres-python 👋 do more with dbt

dbt-postgres-python adapter is the ✨easiest✨ way to run your dbt Python models.

Starting with dbt v1.3, you can now build your dbt models in Python. This leads to some cool use cases that was once difficult to build with SQL alone. Some examples are:

  • Using Python stats libraries to calculate stats
  • Building forecasts
  • Building other predictive models such as classification and clustering

This is fantastic! BUT, there is still one issue though! There is no Python support for Postgres. dbt-postgres-python provides the best environment to run your Python models that works with Postgres!

Project background

This project is based off the dbt-fal project. Thank you FAL-AI for starting that project. Priorities change and FAL-AI in April, 2024 chose to archive that project and focus their efforts elsewhere.

My team at work used dbt-fal, so that we could run python code on postgres. As dbt-fal was not being kept up-to-date with DBT, I chose to pick up that project and bring it up-to-date. As a result, this project will only support Postgres going forward. Support for the FAL CLI has also been dropped.

Getting Started

1. Install dbt-postgres-python

pip install dbt-postgres-python

2. Update your profiles.yml and add the fal adapter

jaffle_shop:
  target: dev_with_fal
  outputs:
    dev_with_fal:
      type: fal  # "fal" type is kept for backwards compatibility
      db_profile: dev_postgres # This points to your main adapter
    dev_postgres:
      type: postgres
      ...

Don't forget to point to your main adapter with the db_profile attribute. This is how the fal adapter knows how to connect to your data warehouse.

3. Add your python models

Add in your python models to your project just as you would your SQL models. Follow DBT's instructions on how to do so.

# a_python_model.py

import ...

def model(dbt, session):

    my_sql_model_df = dbt.ref("my_sql_model")

    final_df = ...  # stuff you can't write in SQL!

    return final_df

4. dbt run!

That is it! It is really that simple 😊

Metadata

Release files for dbt-postgres-python 1.7.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbt-postgres-python 1.7.17
File Size Uploaded
dbt_postgres_python-1.7.17.tar.gz 28.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbt-postgres-python 1.7.17
File Interpreter ABI Platform
dbt_postgres_python-1.7.17-py3-none-any.whl Python 3 none any Details

Total release size: 68.6 kB

Release files / dbt_postgres_python-1.7.17.tar.gz

Download URL dbt_postgres_python-1.7.17.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a79b249b7a1707a034d2b20300d183c7d24c01e3108f02e78c9b1d9f198a54b6
BLAKE2b-256 checksum
How to use checksums
57a1250521425490b25d735c07464bbcac521af80c251c0bbde37d8815a24d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / dbt_postgres_python-1.7.17-py3-none-any.whl

Download URL dbt_postgres_python-1.7.17-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5058bd25b16830c165638a83562611f8b5d1f185f9cfd60beba16fa8006b8a21
BLAKE2b-256 checksum
How to use checksums
cf8b4183d20b7d63a2e137213fb8c6125b92b9051b1348eb43902414844443a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.7.17 This release

2 release files

1.6.16

2 release files

1.5.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page