|
| 1 | +"""Utility for running and logging output from dbt commands |
| 2 | +
|
| 3 | +Enable this utility by installing parsons with a dbt extra: |
| 4 | +`pip install parsons[dbt-redshift]` |
| 5 | +or `pip install parsons[dbt-postgres]` |
| 6 | +or `pip install parsons[dbt-snowflake]` |
| 7 | +or `pip install parsons[dbt-bigquery]` |
| 8 | +
|
| 9 | +To run dbt commands, you will need to have a dbt project directory |
| 10 | +somewhere on the local filesystem. |
| 11 | +
|
| 12 | +The dbt command will inherit environment variables from the python |
| 13 | +process shell, so if your dbt profiles.yml file uses environment |
| 14 | +variables, ensure those are set in python or the parent shell before |
| 15 | +running this dbt utility. |
| 16 | +
|
| 17 | +Logging is handled separately from the dbt run itself. The |
| 18 | +dbtRunner.run method returns a dbtCommandResult object which can be |
| 19 | +passed to a child class of dbtLogger for logging to stdout, slack, |
| 20 | +etc. |
| 21 | +
|
| 22 | +Parsons provides a few example dbtLogger child classes, but for |
| 23 | +best results, design your own! |
| 24 | +
|
| 25 | +Example usage: |
| 26 | +``` |
| 27 | +from parsons.utilities.dbt import ( |
| 28 | + run_dbt_commands, |
| 29 | + dbtLoggerSlack, |
| 30 | + dbtLoggerPython |
| 31 | +) |
| 32 | +
|
| 33 | +run_dbt_commands( |
| 34 | + commands=['run', 'test'], |
| 35 | + dbt_project_directory='/home/ubuntu/code/dbt_project/', |
| 36 | + loggers=[ |
| 37 | + dbtLoggerPython, |
| 38 | + dbtLoggerSlack(slack_webhook=os.environ['SLACK_WEBHOOK']) |
| 39 | + ] |
| 40 | +) |
| 41 | +
|
| 42 | +``` |
| 43 | +
|
| 44 | +""" |
| 45 | + |
| 46 | +from parsons.utilities.dbt.dbt import run_dbt_commands |
| 47 | +from parsons.utilities.dbt.logging import ( |
| 48 | + dbtLoggerMarkdown, |
| 49 | + dbtLoggerSlack, |
| 50 | + dbtLoggerStdout, |
| 51 | + dbtLoggerPython, |
| 52 | +) |
| 53 | + |
| 54 | +__all__ = [ |
| 55 | + "run_dbt_commands", |
| 56 | + "dbtLoggerMarkdown", |
| 57 | + "dbtLoggerSlack", |
| 58 | + "dbtLoggerStdout", |
| 59 | + "dbtLoggerPython", |
| 60 | +] |
0 commit comments