# Welcome to dbt-postgres-python 👋 do more with dbt
dbt-postgres-python adapter is the ✨easiest✨ way to run your [dbt Python models](https://docs.getdbt.com/docs/building-a-dbt-project/building-models/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](https://github.com/fal-ai/dbt-fal) project. Thank you [FAL-AI](https://github.com/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
```yaml
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](https://docs.getdbt.com/docs/build/python-models)
on how to do so.
```python
# 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 😊
Raw data
{
"_id": null,
"home_page": "https://github.com/kudryk/dbt-postgres-python",
"name": "dbt-postgres-python",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "dbt, pandas, fal, runtime",
"author": "Features & Labels",
"author_email": "hello@fal.ai",
"download_url": "https://files.pythonhosted.org/packages/57/a1/250521425490b25d735c07464bbcac521af80c251c0bbde37d8815a24d11/dbt_postgres_python-1.7.17.tar.gz",
"platform": null,
"description": "# Welcome to dbt-postgres-python \ud83d\udc4b do more with dbt\n\ndbt-postgres-python adapter is the \u2728easiest\u2728 way to run your [dbt Python models](https://docs.getdbt.com/docs/building-a-dbt-project/building-models/python-models).\n\nStarting 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:\n\n- Using Python stats libraries to calculate stats\n- Building forecasts\n- Building other predictive models such as classification and clustering\n\nThis 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!\n\n## Project background\n\nThis project is based off the [dbt-fal](https://github.com/fal-ai/dbt-fal) project. Thank you [FAL-AI](https://github.com/fal-ai) for starting that project.\nPriorities change and FAL-AI in April, 2024 chose to archive that project and focus their efforts elsewhere.\n\nMy 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,\nI chose to pick up that project and bring it up-to-date. As a result, this project will only support Postgres going forward.\nSupport for the FAL CLI has also been dropped.\n\n## Getting Started\n\n### 1. Install dbt-postgres-python\n`pip install dbt-postgres-python`\n\n### 2. Update your `profiles.yml` and add the fal adapter\n\n```yaml\njaffle_shop:\n target: dev_with_fal\n outputs:\n dev_with_fal:\n type: fal # \"fal\" type is kept for backwards compatibility\n db_profile: dev_postgres # This points to your main adapter\n dev_postgres:\n type: postgres\n ...\n```\n\nDon'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.\n\n### 3. Add your python models\n\nAdd in your python models to your project just as you would your SQL models. Follow DBT's [instructions](https://docs.getdbt.com/docs/build/python-models) \non how to do so.\n\n```python\n# a_python_model.py\n\nimport ...\n\ndef model(dbt, session):\n\n my_sql_model_df = dbt.ref(\"my_sql_model\")\n\n final_df = ... # stuff you can't write in SQL!\n\n return final_df\n```\n\n### 4. `dbt run`!\nThat is it! It is really that simple \ud83d\ude0a\n\n",
"bugtrack_url": null,
"license": null,
"summary": "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.",
"version": "1.7.17",
"project_urls": {
"Homepage": "https://github.com/kudryk/dbt-postgres-python",
"Repository": "https://github.com/kudryk/dbt-postgres-python"
},
"split_keywords": [
"dbt",
" pandas",
" fal",
" runtime"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cf8b4183d20b7d63a2e137213fb8c6125b92b9051b1348eb43902414844443a4",
"md5": "b387f6fd581b1c8d42096635e6712d61",
"sha256": "5058bd25b16830c165638a83562611f8b5d1f185f9cfd60beba16fa8006b8a21"
},
"downloads": -1,
"filename": "dbt_postgres_python-1.7.17-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b387f6fd581b1c8d42096635e6712d61",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 39969,
"upload_time": "2024-06-17T20:14:57",
"upload_time_iso_8601": "2024-06-17T20:14:57.663756Z",
"url": "https://files.pythonhosted.org/packages/cf/8b/4183d20b7d63a2e137213fb8c6125b92b9051b1348eb43902414844443a4/dbt_postgres_python-1.7.17-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "57a1250521425490b25d735c07464bbcac521af80c251c0bbde37d8815a24d11",
"md5": "15b9229a34bcd2161a3080ea33dc3128",
"sha256": "a79b249b7a1707a034d2b20300d183c7d24c01e3108f02e78c9b1d9f198a54b6"
},
"downloads": -1,
"filename": "dbt_postgres_python-1.7.17.tar.gz",
"has_sig": false,
"md5_digest": "15b9229a34bcd2161a3080ea33dc3128",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 28635,
"upload_time": "2024-06-17T20:15:41",
"upload_time_iso_8601": "2024-06-17T20:15:41.607313Z",
"url": "https://files.pythonhosted.org/packages/57/a1/250521425490b25d735c07464bbcac521af80c251c0bbde37d8815a24d11/dbt_postgres_python-1.7.17.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-17 20:15:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kudryk",
"github_project": "dbt-postgres-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "dbt-postgres-python"
}