Skip to main content

Run python scripts from any dbt project. This project is based on the project https://github.com/fal-ai/fal initially authored by FAL.AI.

Project description

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 😊

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_postgres_python-1.7.17.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

dbt_postgres_python-1.7.17-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file dbt_postgres_python-1.7.17.tar.gz.

File metadata

  • Download URL: dbt_postgres_python-1.7.17.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for dbt_postgres_python-1.7.17.tar.gz
Algorithm Hash digest
SHA256 a79b249b7a1707a034d2b20300d183c7d24c01e3108f02e78c9b1d9f198a54b6
MD5 15b9229a34bcd2161a3080ea33dc3128
BLAKE2b-256 57a1250521425490b25d735c07464bbcac521af80c251c0bbde37d8815a24d11

See more details on using hashes here.

File details

Details for the file dbt_postgres_python-1.7.17-py3-none-any.whl.

File metadata

File hashes

Hashes for dbt_postgres_python-1.7.17-py3-none-any.whl
Algorithm Hash digest
SHA256 5058bd25b16830c165638a83562611f8b5d1f185f9cfd60beba16fa8006b8a21
MD5 b387f6fd581b1c8d42096635e6712d61
BLAKE2b-256 cf8b4183d20b7d63a2e137213fb8c6125b92b9051b1348eb43902414844443a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page