dbt-orchestra 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. dbt_orchestra-0.4.0/LICENSE +93 -0
  2. dbt_orchestra-0.4.0/PKG-INFO +242 -0
  3. dbt_orchestra-0.4.0/README.md +197 -0
  4. dbt_orchestra-0.4.0/pyproject.toml +67 -0
  5. dbt_orchestra-0.4.0/setup.cfg +4 -0
  6. dbt_orchestra-0.4.0/src/dbt_orchestra.egg-info/PKG-INFO +242 -0
  7. dbt_orchestra-0.4.0/src/dbt_orchestra.egg-info/SOURCES.txt +45 -0
  8. dbt_orchestra-0.4.0/src/dbt_orchestra.egg-info/dependency_links.txt +1 -0
  9. dbt_orchestra-0.4.0/src/dbt_orchestra.egg-info/entry_points.txt +2 -0
  10. dbt_orchestra-0.4.0/src/dbt_orchestra.egg-info/requires.txt +26 -0
  11. dbt_orchestra-0.4.0/src/dbt_orchestra.egg-info/top_level.txt +1 -0
  12. dbt_orchestra-0.4.0/src/orchestra_dbt/__init__.py +0 -0
  13. dbt_orchestra-0.4.0/src/orchestra_dbt/asset_external_id.py +25 -0
  14. dbt_orchestra-0.4.0/src/orchestra_dbt/build_after.py +155 -0
  15. dbt_orchestra-0.4.0/src/orchestra_dbt/checksum.py +26 -0
  16. dbt_orchestra-0.4.0/src/orchestra_dbt/cli.py +217 -0
  17. dbt_orchestra-0.4.0/src/orchestra_dbt/compatibility.py +8 -0
  18. dbt_orchestra-0.4.0/src/orchestra_dbt/config.py +123 -0
  19. dbt_orchestra-0.4.0/src/orchestra_dbt/constants.py +6 -0
  20. dbt_orchestra-0.4.0/src/orchestra_dbt/dag.py +153 -0
  21. dbt_orchestra-0.4.0/src/orchestra_dbt/logger.py +43 -0
  22. dbt_orchestra-0.4.0/src/orchestra_dbt/ls.py +43 -0
  23. dbt_orchestra-0.4.0/src/orchestra_dbt/models.py +67 -0
  24. dbt_orchestra-0.4.0/src/orchestra_dbt/modify.py +76 -0
  25. dbt_orchestra-0.4.0/src/orchestra_dbt/orchestra.py +16 -0
  26. dbt_orchestra-0.4.0/src/orchestra_dbt/patcher.py +202 -0
  27. dbt_orchestra-0.4.0/src/orchestra_dbt/project_discovery.py +24 -0
  28. dbt_orchestra-0.4.0/src/orchestra_dbt/sao.py +181 -0
  29. dbt_orchestra-0.4.0/src/orchestra_dbt/source_freshness/__init__.py +73 -0
  30. dbt_orchestra-0.4.0/src/orchestra_dbt/source_freshness/fallbacks/__init__.py +11 -0
  31. dbt_orchestra-0.4.0/src/orchestra_dbt/source_freshness/fallbacks/common.py +58 -0
  32. dbt_orchestra-0.4.0/src/orchestra_dbt/source_freshness/fallbacks/databricks.py +40 -0
  33. dbt_orchestra-0.4.0/src/orchestra_dbt/source_freshness/fallbacks/registry.py +22 -0
  34. dbt_orchestra-0.4.0/src/orchestra_dbt/state.py +81 -0
  35. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/__init__.py +8 -0
  36. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/base.py +9 -0
  37. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/factory.py +62 -0
  38. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/http.py +70 -0
  39. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/local_file.py +56 -0
  40. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/logging.py +24 -0
  41. dbt_orchestra-0.4.0/src/orchestra_dbt/state_backends/s3.py +71 -0
  42. dbt_orchestra-0.4.0/src/orchestra_dbt/state_errors.py +6 -0
  43. dbt_orchestra-0.4.0/src/orchestra_dbt/state_filters.py +9 -0
  44. dbt_orchestra-0.4.0/src/orchestra_dbt/state_storage.py +5 -0
  45. dbt_orchestra-0.4.0/src/orchestra_dbt/state_types.py +56 -0
  46. dbt_orchestra-0.4.0/src/orchestra_dbt/target_finder.py +8 -0
  47. dbt_orchestra-0.4.0/src/orchestra_dbt/utils.py +23 -0
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that
84
+ organization. **control** means ownership of substantially all the assets of an
85
+ entity, or the power to direct its management and policies by vote, contract, or
86
+ otherwise. Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: dbt-orchestra
3
+ Version: 0.4.0
4
+ Summary: Orchestra wrapper for dbt Core - allows for stateful orchestration of dbt Core projects.
5
+ Author: Orchestra Technologies
6
+ License-Expression: Elastic-2.0
7
+ Project-URL: Repository, https://github.com/orchestra-hq/sao-paolo
8
+ Project-URL: Issues, https://github.com/orchestra-hq/sao-paolo/issues
9
+ Project-URL: Changelog, https://github.com/orchestra-hq/sao-paolo/blob/main/CHANGELOG.md
10
+ Project-URL: Security, https://github.com/orchestra-hq/sao-paolo/security/policy
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Build Tools
19
+ Requires-Python: <3.14,>=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: click
23
+ Requires-Dist: httpx
24
+ Requires-Dist: packaging
25
+ Requires-Dist: pydantic
26
+ Requires-Dist: pytz
27
+ Requires-Dist: pyyaml
28
+ Provides-Extra: dev
29
+ Requires-Dist: basedpyright; extra == "dev"
30
+ Requires-Dist: boto3; extra == "dev"
31
+ Requires-Dist: dbt-core<1.12,>=1.10; extra == "dev"
32
+ Requires-Dist: moto[s3]; extra == "dev"
33
+ Requires-Dist: pytest-httpx; extra == "dev"
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Requires-Dist: ruff; extra == "dev"
36
+ Provides-Extra: adapters
37
+ Requires-Dist: dbt-postgres; extra == "adapters"
38
+ Provides-Extra: debug
39
+ Requires-Dist: awscrt; extra == "debug"
40
+ Requires-Dist: boto3; extra == "debug"
41
+ Requires-Dist: graphviz; extra == "debug"
42
+ Provides-Extra: s3
43
+ Requires-Dist: boto3; extra == "s3"
44
+ Dynamic: license-file
45
+
46
+ # dbt-orchestra
47
+
48
+ ## Compatibility
49
+
50
+ - **Python:** 3.11, 3.12, and 3.13 only (see `requires-python` in `pyproject.toml`).
51
+ - **dbt-core:** 1.10.x and 1.11.x when using stateful orchestration.
52
+
53
+ ## Installing
54
+
55
+ ```bash
56
+ python3 -m venv .venv
57
+ source .venv/bin/activate
58
+ uv sync --extra dev
59
+ # Optional: Snowflake/Databricks adapters for local runs
60
+ # uv sync --extra dev --extra adapters
61
+ ```
62
+
63
+ ## Tutorial dbt project
64
+
65
+ A minimal dbt Core project lives under `[tutorial/](tutorial/)`. This is used for testing and CI.
66
+
67
+ ## Development
68
+
69
+ 1. Create a branch
70
+ 1. Add the code and unit tests
71
+ 1. Where possible, [test locally](#running-locally)
72
+ 1. Test in Orchestra with the branch
73
+ 1. Raise a PR
74
+
75
+ Pull requests run GitHub Actions: unit tests, static checks, `dbt build` for `tutorial/dbt` against Postgres, and an Orchestra pipeline via the [Orchestra Run Pipeline Action](https://github.com/orchestra-hq/run-pipeline).
76
+
77
+ ## State Aware Orchestration
78
+
79
+ When stateful orchestration is enabled, the CLI loads and saves [dbt Core state](https://docs.getdbt.com/). Enable it with `use_stateful = true` under `[tool.orchestra_dbt]`, or set `ORCHESTRA_USE_STATEFUL=true`. That state is the same JSON shape regardless of the backend used.
80
+
81
+ **Do not put secrets in `pyproject.toml`.** Use environment variables (or your platform’s secret store) for `ORCHESTRA_API_KEY`.
82
+
83
+ ### Configuration precedence
84
+
85
+ For non-secret options, **if an environment variable is set, it overrides** values from `[tool.orchestra_dbt]`; otherwise the value from `pyproject.toml` is used, then the built-in default.
86
+
87
+ ### `[tool.orchestra_dbt]` options
88
+
89
+ | Key | Type | Default | Purpose |
90
+ | ------------------------ | ----------------- | ------- | ------------------------------------------------------------------------- |
91
+ | `state_file` | string (optional) | — | Local JSON path or `s3://bucket/key` for state (see backend table below). |
92
+ | `use_stateful` | bool | `false` | Turn on stateful orchestration for supported dbt commands. |
93
+ | `orchestra_env` | string | `app` | Orchestra deployment: `app`, `stage`, or `dev` (HTTP API host). |
94
+ | `local_run` | bool | `true` | After reuse, revert patched files (typical for local iteration). |
95
+ | `debug` | bool | `false` | Verbose debug logging. |
96
+ | `integration_account_id` | string (optional) | — | When set, filter state keys to this integration account prefix. |
97
+
98
+ Equivalent environment overrides (when set): `ORCHESTRA_USE_STATEFUL`, `ORCHESTRA_ENV`, `ORCHESTRA_LOCAL_RUN`, `ORCHESTRA_DBT_DEBUG`, `ORCHESTRA_INTEGRATION_ACCOUNT_ID`.
99
+
100
+ ### Choosing HTTP (Orchestra cloud), a local JSON file, or S3
101
+
102
+ The CLI discovers `pyproject.toml` by walking upward from the current working directory. `[tool.orchestra_dbt]` is read from that file when present.
103
+
104
+ | Priority | Setting | Effect |
105
+ | -------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
106
+ | 1 | `ORCHESTRA_API_KEY` | Load/save state via Orchestra HTTP. The Orchestra environment is `orchestra_env` in pyproject (default `app`) or `ORCHESTRA_ENV` when set; must be one of `app`, `stage`, or `dev`. When the API key is set, `ORCHESTRA_STATE_FILE` and `state_file` in `pyproject.toml` are **ignored** for choosing the state backend. |
107
+ | 2 | `ORCHESTRA_STATE_FILE` | Path to a JSON file, or `s3://bucket/key` for an object in S3. Relative file paths are resolved from the current working directory. Used only when `ORCHESTRA_API_KEY` is unset. |
108
+ | 3 | `[tool.orchestra_dbt]` / `state_file` in `pyproject.toml` | Path to a JSON file, or `s3://bucket/key`. Relative file paths are resolved from the directory that contains the **discovered** `pyproject.toml`; absolute paths are used as-is. Used only when `ORCHESTRA_API_KEY` is unset and `ORCHESTRA_STATE_FILE` is unset. |
109
+
110
+ If an effective local path or S3 URI is configured (rows 2 or 3), that **file** or **S3** backend is used and an API key is not required for state. If `ORCHESTRA_API_KEY` is set (row 1), the **HTTP backend** is used regardless of file settings.
111
+
112
+ For S3, install the optional dependency (`pip install 'dbt-orchestra[s3]'` or `uv sync --extra s3`). Credentials and region follow the usual [AWS SDK resolution](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) (environment variables, shared config, IAM role, etc.). If the object does not exist yet, load starts with an empty state and save creates the object.
113
+
114
+ Stateful orchestration only runs for `dbt build`, `dbt run`, and `dbt test`. Other dbt subcommands are passed through to dbt unchanged.
115
+
116
+ ### Warehouse adapters and implicit source freshness
117
+
118
+ Stateful reuse uses `dbt source freshness` results. When a source defines `**loaded_at_field`** or `**loaded_at_query**`, dbt’s normal freshness logic runs on every adapter Orchestra supports through dbt Core.
119
+
120
+ When **both** are omitted, Orchestra can still run **adapter-specific** SQL to infer `max_loaded_at` (see `src/orchestra_dbt/source_freshness/`). Only the adapters below register that path today; the mapping is keyed by `FreshnessRunner.adapter.type()`.
121
+
122
+ | Warehouse | dbt adapter type (typical) | Implicit freshness (no `loaded_at_*`) |
123
+ | -------------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
124
+ | **Databricks** | `databricks` | **Supported** — uses `DESCRIBE HISTORY` on the source relation. |
125
+ | **Snowflake** | `snowflake` | **Use `loaded_at_field` or `loaded_at_query`** — no Orchestra fallback; standard dbt freshness. |
126
+ | **Microsoft Fabric** | `fabric` | Same as Snowflake — configure `loaded_at_`*; no Orchestra fallback. |
127
+ | **PostgreSQL** | `postgres` | Same as Snowflake — configure `loaded_at_`*; no Orchestra fallback. |
128
+ | **DuckDB** | `duckdb` | **Not supported** |
129
+ | **Other adapters** | varies | No Orchestra fallback unless listed above; use `loaded_at_`* or verify dbt’s default behavior for your warehouse. |
130
+
131
+ For adapters without a registered fallback, if both `loaded_at` settings are missing, Orchestra follows dbt’s `FreshnessRunner` behavior (which may surface as warnings or a non-actionable result depending on dbt and the warehouse).
132
+
133
+ ### Runtime behavior by command and mode
134
+
135
+ | Stateful enabled | dbt command | Behavior |
136
+ | ---------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
137
+ | `false` | any command | `orc` passes through to dbt with no state load/save. |
138
+ | `true` | `build`, `run`, `test` | `orc` loads state, computes reusable nodes, patches clean nodes, runs dbt, updates and saves state. |
139
+ | `true` | `build`, `run`, `test` + `--full-refresh` | `orc` skips reuse decisions for this invocation, runs dbt directly, then still updates/saves state after execution. |
140
+ | `true` | other command (for example `seed`, `docs generate`) | `orc` passes through to dbt unchanged. |
141
+
142
+ Example optional snippet in `pyproject.toml`:
143
+
144
+ ```toml
145
+ [tool.orchestra_dbt]
146
+ use_stateful = true
147
+ orchestra_env = "dev"
148
+ state_file = ".orchestra/dbt_state.json"
149
+ ```
150
+
151
+ Add `.orchestra/` (or your chosen path) to `.gitignore` if the file should not be committed.
152
+
153
+ ### Bootstrapping a new local state file
154
+
155
+ If the configured **local** file does not exist, the CLI fails with an error (it does not silently start from empty state). Create a minimal file first, for example:
156
+
157
+ ```bash
158
+ mkdir -p .orchestra
159
+ echo '{"state":{}}' > .orchestra/dbt_state.json
160
+ ```
161
+
162
+ ## Running locally
163
+
164
+ Orchestra HTTP (requires an API key from Orchestra). Setting `ORCHESTRA_API_KEY` selects the HTTP backend; file-related settings are ignored. Put non-secret defaults in `pyproject.toml` and only export the API key:
165
+
166
+ ```toml
167
+ [tool.orchestra_dbt]
168
+ use_stateful = true
169
+ orchestra_env = "dev"
170
+ local_run = true
171
+ ```
172
+
173
+ ```bash
174
+ export ORCHESTRA_API_KEY=<API_KEY>
175
+ orc dbt run --target snowflake
176
+ ```
177
+
178
+ You can still override with env vars (for example `ORCHESTRA_ENV=stage`) when needed.
179
+
180
+ Local JSON file (after creating the file as above): **unset** `ORCHESTRA_API_KEY` so `ORCHESTRA_STATE_FILE` or `state_file` in `pyproject.toml` is used.
181
+
182
+ ```toml
183
+ [tool.orchestra_dbt]
184
+ use_stateful = true
185
+ state_file = ".orchestra/dbt_state.json"
186
+ local_run = true
187
+ ```
188
+
189
+ ```bash
190
+ orc dbt run --target snowflake
191
+ ```
192
+
193
+ ## Debugging
194
+
195
+ To debug pipelines, there are some local files and scripts.
196
+
197
+ To install the required dependencies, run:
198
+
199
+ ```bash
200
+ uv sync --extra dev --extra debug
201
+ ```
202
+
203
+ Ask @ojc-orchestra for access to the scripts:
204
+
205
+ - `dynamo_state.py`: loads state from DynamoDB into a local JSON file `local_state.json`
206
+ - `visualise.py`: loads ops from `ops.json` and visualises them in a DAG structure. This can be loaded in a browser by opening the resulting HTML file, `ops_dag.html`.
207
+
208
+ ## Testing
209
+
210
+ ```bash
211
+ pytest
212
+ ```
213
+
214
+ Without Postgres, the tutorial `dbt build` integration test is skipped. To run it locally, start Postgres, set `PGHOST`, `PGDATABASE`, and related variables (see `[tutorial/README.md](tutorial/README.md)`), then run `pytest tests/integration/test_tutorial_dbt.py`.
215
+
216
+ For the optional DAG integration test (`tests/integration/test_local.py`), place both `local_state.json` and `local_manifest.json` in the repository root. `local_state.json` can be created with `dynamo_state.py` (see above), and `local_manifest.json` can be downloaded from a representative dbt run.
217
+
218
+ Run only unit or integration tests:
219
+
220
+ ```bash
221
+ pytest tests/unit/
222
+ pytest tests/integration/
223
+ ```
224
+
225
+ Run a specific test module or case:
226
+
227
+ ```bash
228
+ pytest tests/unit/test_state.py
229
+ pytest tests/unit/test_state.py::TestLoadState::test_load_state_success
230
+ ```
231
+
232
+ ## Linting
233
+
234
+ ```bash
235
+ ruff check . && ruff format --check . && basedpyright
236
+ ```
237
+
238
+ To automatically fix issues:
239
+
240
+ ```bash
241
+ ruff check --fix . && ruff format . && basedpyright
242
+ ```
@@ -0,0 +1,197 @@
1
+ # dbt-orchestra
2
+
3
+ ## Compatibility
4
+
5
+ - **Python:** 3.11, 3.12, and 3.13 only (see `requires-python` in `pyproject.toml`).
6
+ - **dbt-core:** 1.10.x and 1.11.x when using stateful orchestration.
7
+
8
+ ## Installing
9
+
10
+ ```bash
11
+ python3 -m venv .venv
12
+ source .venv/bin/activate
13
+ uv sync --extra dev
14
+ # Optional: Snowflake/Databricks adapters for local runs
15
+ # uv sync --extra dev --extra adapters
16
+ ```
17
+
18
+ ## Tutorial dbt project
19
+
20
+ A minimal dbt Core project lives under `[tutorial/](tutorial/)`. This is used for testing and CI.
21
+
22
+ ## Development
23
+
24
+ 1. Create a branch
25
+ 1. Add the code and unit tests
26
+ 1. Where possible, [test locally](#running-locally)
27
+ 1. Test in Orchestra with the branch
28
+ 1. Raise a PR
29
+
30
+ Pull requests run GitHub Actions: unit tests, static checks, `dbt build` for `tutorial/dbt` against Postgres, and an Orchestra pipeline via the [Orchestra Run Pipeline Action](https://github.com/orchestra-hq/run-pipeline).
31
+
32
+ ## State Aware Orchestration
33
+
34
+ When stateful orchestration is enabled, the CLI loads and saves [dbt Core state](https://docs.getdbt.com/). Enable it with `use_stateful = true` under `[tool.orchestra_dbt]`, or set `ORCHESTRA_USE_STATEFUL=true`. That state is the same JSON shape regardless of the backend used.
35
+
36
+ **Do not put secrets in `pyproject.toml`.** Use environment variables (or your platform’s secret store) for `ORCHESTRA_API_KEY`.
37
+
38
+ ### Configuration precedence
39
+
40
+ For non-secret options, **if an environment variable is set, it overrides** values from `[tool.orchestra_dbt]`; otherwise the value from `pyproject.toml` is used, then the built-in default.
41
+
42
+ ### `[tool.orchestra_dbt]` options
43
+
44
+ | Key | Type | Default | Purpose |
45
+ | ------------------------ | ----------------- | ------- | ------------------------------------------------------------------------- |
46
+ | `state_file` | string (optional) | — | Local JSON path or `s3://bucket/key` for state (see backend table below). |
47
+ | `use_stateful` | bool | `false` | Turn on stateful orchestration for supported dbt commands. |
48
+ | `orchestra_env` | string | `app` | Orchestra deployment: `app`, `stage`, or `dev` (HTTP API host). |
49
+ | `local_run` | bool | `true` | After reuse, revert patched files (typical for local iteration). |
50
+ | `debug` | bool | `false` | Verbose debug logging. |
51
+ | `integration_account_id` | string (optional) | — | When set, filter state keys to this integration account prefix. |
52
+
53
+ Equivalent environment overrides (when set): `ORCHESTRA_USE_STATEFUL`, `ORCHESTRA_ENV`, `ORCHESTRA_LOCAL_RUN`, `ORCHESTRA_DBT_DEBUG`, `ORCHESTRA_INTEGRATION_ACCOUNT_ID`.
54
+
55
+ ### Choosing HTTP (Orchestra cloud), a local JSON file, or S3
56
+
57
+ The CLI discovers `pyproject.toml` by walking upward from the current working directory. `[tool.orchestra_dbt]` is read from that file when present.
58
+
59
+ | Priority | Setting | Effect |
60
+ | -------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
61
+ | 1 | `ORCHESTRA_API_KEY` | Load/save state via Orchestra HTTP. The Orchestra environment is `orchestra_env` in pyproject (default `app`) or `ORCHESTRA_ENV` when set; must be one of `app`, `stage`, or `dev`. When the API key is set, `ORCHESTRA_STATE_FILE` and `state_file` in `pyproject.toml` are **ignored** for choosing the state backend. |
62
+ | 2 | `ORCHESTRA_STATE_FILE` | Path to a JSON file, or `s3://bucket/key` for an object in S3. Relative file paths are resolved from the current working directory. Used only when `ORCHESTRA_API_KEY` is unset. |
63
+ | 3 | `[tool.orchestra_dbt]` / `state_file` in `pyproject.toml` | Path to a JSON file, or `s3://bucket/key`. Relative file paths are resolved from the directory that contains the **discovered** `pyproject.toml`; absolute paths are used as-is. Used only when `ORCHESTRA_API_KEY` is unset and `ORCHESTRA_STATE_FILE` is unset. |
64
+
65
+ If an effective local path or S3 URI is configured (rows 2 or 3), that **file** or **S3** backend is used and an API key is not required for state. If `ORCHESTRA_API_KEY` is set (row 1), the **HTTP backend** is used regardless of file settings.
66
+
67
+ For S3, install the optional dependency (`pip install 'dbt-orchestra[s3]'` or `uv sync --extra s3`). Credentials and region follow the usual [AWS SDK resolution](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) (environment variables, shared config, IAM role, etc.). If the object does not exist yet, load starts with an empty state and save creates the object.
68
+
69
+ Stateful orchestration only runs for `dbt build`, `dbt run`, and `dbt test`. Other dbt subcommands are passed through to dbt unchanged.
70
+
71
+ ### Warehouse adapters and implicit source freshness
72
+
73
+ Stateful reuse uses `dbt source freshness` results. When a source defines `**loaded_at_field`** or `**loaded_at_query**`, dbt’s normal freshness logic runs on every adapter Orchestra supports through dbt Core.
74
+
75
+ When **both** are omitted, Orchestra can still run **adapter-specific** SQL to infer `max_loaded_at` (see `src/orchestra_dbt/source_freshness/`). Only the adapters below register that path today; the mapping is keyed by `FreshnessRunner.adapter.type()`.
76
+
77
+ | Warehouse | dbt adapter type (typical) | Implicit freshness (no `loaded_at_*`) |
78
+ | -------------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
79
+ | **Databricks** | `databricks` | **Supported** — uses `DESCRIBE HISTORY` on the source relation. |
80
+ | **Snowflake** | `snowflake` | **Use `loaded_at_field` or `loaded_at_query`** — no Orchestra fallback; standard dbt freshness. |
81
+ | **Microsoft Fabric** | `fabric` | Same as Snowflake — configure `loaded_at_`*; no Orchestra fallback. |
82
+ | **PostgreSQL** | `postgres` | Same as Snowflake — configure `loaded_at_`*; no Orchestra fallback. |
83
+ | **DuckDB** | `duckdb` | **Not supported** |
84
+ | **Other adapters** | varies | No Orchestra fallback unless listed above; use `loaded_at_`* or verify dbt’s default behavior for your warehouse. |
85
+
86
+ For adapters without a registered fallback, if both `loaded_at` settings are missing, Orchestra follows dbt’s `FreshnessRunner` behavior (which may surface as warnings or a non-actionable result depending on dbt and the warehouse).
87
+
88
+ ### Runtime behavior by command and mode
89
+
90
+ | Stateful enabled | dbt command | Behavior |
91
+ | ---------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
92
+ | `false` | any command | `orc` passes through to dbt with no state load/save. |
93
+ | `true` | `build`, `run`, `test` | `orc` loads state, computes reusable nodes, patches clean nodes, runs dbt, updates and saves state. |
94
+ | `true` | `build`, `run`, `test` + `--full-refresh` | `orc` skips reuse decisions for this invocation, runs dbt directly, then still updates/saves state after execution. |
95
+ | `true` | other command (for example `seed`, `docs generate`) | `orc` passes through to dbt unchanged. |
96
+
97
+ Example optional snippet in `pyproject.toml`:
98
+
99
+ ```toml
100
+ [tool.orchestra_dbt]
101
+ use_stateful = true
102
+ orchestra_env = "dev"
103
+ state_file = ".orchestra/dbt_state.json"
104
+ ```
105
+
106
+ Add `.orchestra/` (or your chosen path) to `.gitignore` if the file should not be committed.
107
+
108
+ ### Bootstrapping a new local state file
109
+
110
+ If the configured **local** file does not exist, the CLI fails with an error (it does not silently start from empty state). Create a minimal file first, for example:
111
+
112
+ ```bash
113
+ mkdir -p .orchestra
114
+ echo '{"state":{}}' > .orchestra/dbt_state.json
115
+ ```
116
+
117
+ ## Running locally
118
+
119
+ Orchestra HTTP (requires an API key from Orchestra). Setting `ORCHESTRA_API_KEY` selects the HTTP backend; file-related settings are ignored. Put non-secret defaults in `pyproject.toml` and only export the API key:
120
+
121
+ ```toml
122
+ [tool.orchestra_dbt]
123
+ use_stateful = true
124
+ orchestra_env = "dev"
125
+ local_run = true
126
+ ```
127
+
128
+ ```bash
129
+ export ORCHESTRA_API_KEY=<API_KEY>
130
+ orc dbt run --target snowflake
131
+ ```
132
+
133
+ You can still override with env vars (for example `ORCHESTRA_ENV=stage`) when needed.
134
+
135
+ Local JSON file (after creating the file as above): **unset** `ORCHESTRA_API_KEY` so `ORCHESTRA_STATE_FILE` or `state_file` in `pyproject.toml` is used.
136
+
137
+ ```toml
138
+ [tool.orchestra_dbt]
139
+ use_stateful = true
140
+ state_file = ".orchestra/dbt_state.json"
141
+ local_run = true
142
+ ```
143
+
144
+ ```bash
145
+ orc dbt run --target snowflake
146
+ ```
147
+
148
+ ## Debugging
149
+
150
+ To debug pipelines, there are some local files and scripts.
151
+
152
+ To install the required dependencies, run:
153
+
154
+ ```bash
155
+ uv sync --extra dev --extra debug
156
+ ```
157
+
158
+ Ask @ojc-orchestra for access to the scripts:
159
+
160
+ - `dynamo_state.py`: loads state from DynamoDB into a local JSON file `local_state.json`
161
+ - `visualise.py`: loads ops from `ops.json` and visualises them in a DAG structure. This can be loaded in a browser by opening the resulting HTML file, `ops_dag.html`.
162
+
163
+ ## Testing
164
+
165
+ ```bash
166
+ pytest
167
+ ```
168
+
169
+ Without Postgres, the tutorial `dbt build` integration test is skipped. To run it locally, start Postgres, set `PGHOST`, `PGDATABASE`, and related variables (see `[tutorial/README.md](tutorial/README.md)`), then run `pytest tests/integration/test_tutorial_dbt.py`.
170
+
171
+ For the optional DAG integration test (`tests/integration/test_local.py`), place both `local_state.json` and `local_manifest.json` in the repository root. `local_state.json` can be created with `dynamo_state.py` (see above), and `local_manifest.json` can be downloaded from a representative dbt run.
172
+
173
+ Run only unit or integration tests:
174
+
175
+ ```bash
176
+ pytest tests/unit/
177
+ pytest tests/integration/
178
+ ```
179
+
180
+ Run a specific test module or case:
181
+
182
+ ```bash
183
+ pytest tests/unit/test_state.py
184
+ pytest tests/unit/test_state.py::TestLoadState::test_load_state_success
185
+ ```
186
+
187
+ ## Linting
188
+
189
+ ```bash
190
+ ruff check . && ruff format --check . && basedpyright
191
+ ```
192
+
193
+ To automatically fix issues:
194
+
195
+ ```bash
196
+ ruff check --fix . && ruff format . && basedpyright
197
+ ```
@@ -0,0 +1,67 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dbt-orchestra"
7
+ version = "0.4.0"
8
+ description = "Orchestra wrapper for dbt Core - allows for stateful orchestration of dbt Core projects."
9
+ authors = [{ name = "Orchestra Technologies" }]
10
+ license = "Elastic-2.0"
11
+ license-files = ["LICENSE"]
12
+ readme = { file = "README.md", content-type = "text/markdown" }
13
+ requires-python = ">=3.11,<3.14"
14
+ dependencies = ["click", "httpx", "packaging", "pydantic", "pytz", "pyyaml"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Software Development :: Build Tools",
24
+ ]
25
+
26
+ [project.urls]
27
+ Repository = "https://github.com/orchestra-hq/sao-paolo"
28
+ Issues = "https://github.com/orchestra-hq/sao-paolo/issues"
29
+ Changelog = "https://github.com/orchestra-hq/sao-paolo/blob/main/CHANGELOG.md"
30
+ Security = "https://github.com/orchestra-hq/sao-paolo/security/policy"
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "basedpyright",
35
+ "boto3",
36
+ "dbt-core>=1.10,<1.12",
37
+ "moto[s3]",
38
+ "pytest-httpx",
39
+ "pytest",
40
+ "ruff",
41
+ ]
42
+
43
+ # Warehouse adapters (optional). Not required for tests.
44
+ adapters = ["dbt-postgres"]
45
+
46
+ # Debug dependencies (optional).
47
+ debug = ["awscrt", "boto3", "graphviz"]
48
+
49
+ # S3-backed state (optional; boto3 loaded only when S3 URI is configured)
50
+ s3 = ["boto3"]
51
+
52
+ [project.scripts]
53
+ orc = "orchestra_dbt.cli:main"
54
+
55
+ [tool.basedpyright]
56
+ typeCheckingMode = "basic"
57
+ include = ["src", "tests"]
58
+
59
+ [tool.pytest.ini_options]
60
+ pythonpath = ["src"]
61
+ testpaths = ["tests"]
62
+
63
+ [tool.setuptools.packages.find]
64
+ where = ["src"]
65
+
66
+ [tool.uv]
67
+ package = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+