xref 0.1.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.
- xref-0.1.0/LICENSE +177 -0
- xref-0.1.0/PKG-INFO +181 -0
- xref-0.1.0/README.md +162 -0
- xref-0.1.0/pyproject.toml +66 -0
- xref-0.1.0/pyproject.toml.orig +61 -0
- xref-0.1.0/src/xref/__init__.py +1 -0
- xref-0.1.0/src/xref/_typing.py +13 -0
- xref-0.1.0/src/xref/cli.py +138 -0
- xref-0.1.0/src/xref/config.py +88 -0
- xref-0.1.0/src/xref/errors.py +2 -0
- xref-0.1.0/src/xref/manifest.py +128 -0
- xref-0.1.0/src/xref/operations.py +196 -0
- xref-0.1.0/src/xref/packages.py +160 -0
- xref-0.1.0/src/xref/published.py +126 -0
- xref-0.1.0/src/xref/store.py +139 -0
- xref-0.1.0/src/xref/stubs.py +108 -0
xref-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
xref-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xref
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cross-project refs for dbt v2 without the dbt platform.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: fsspec>=2024.6
|
|
8
|
+
Requires-Dist: pydantic>=2.14.3
|
|
9
|
+
Requires-Dist: pyyaml>=6
|
|
10
|
+
Requires-Dist: typer>=0.29.1
|
|
11
|
+
Requires-Dist: adlfs>=2026.8.0 ; extra == 'azure'
|
|
12
|
+
Requires-Dist: gcsfs>=2026.10.1 ; extra == 'gcs'
|
|
13
|
+
Requires-Dist: s3fs>=2026.9.0 ; extra == 's3'
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Provides-Extra: azure
|
|
16
|
+
Provides-Extra: gcs
|
|
17
|
+
Provides-Extra: s3
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# xref
|
|
21
|
+
|
|
22
|
+
Cross-project `ref('project', 'model')` for dbt v2, without a dbt platform plan.
|
|
23
|
+
|
|
24
|
+
A producer project publishes a slim copy of its manifest after each run. A
|
|
25
|
+
consumer project syncs it before `dbt deps`, and xref writes a local dbt package
|
|
26
|
+
with one ephemeral stub per public model:
|
|
27
|
+
|
|
28
|
+
```sql
|
|
29
|
+
-- .xref/core_platform/models/dim_customers.sql (generated)
|
|
30
|
+
{{ config(materialized='ephemeral') }}
|
|
31
|
+
select * from "analytics"."core"."dim_customers"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
dbt then resolves `{{ ref('core_platform', 'dim_customers') }}` as an ordinary
|
|
35
|
+
package ref. It compiles to a CTE over the producer's table, lineage shows the
|
|
36
|
+
upstream model, and `dbt build` skips the stubs (`no-op`), so nothing upstream
|
|
37
|
+
is rebuilt. Tested on dbt v2.0.11, both `dbt-oss` and the proprietary `dbt`.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
xref is not on PyPI yet. Install from GitHub, with the extra for your store:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
pip install "xref[s3] @ git+https://github.com/dietofworms/xref"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Extras: `s3` (S3 and S3-compatible), `gcs` (Google Cloud Storage), `azure`
|
|
48
|
+
(Azure Blob / ADLS). A local or network directory needs no extra.
|
|
49
|
+
|
|
50
|
+
## Producer: publish after each run
|
|
51
|
+
|
|
52
|
+
1. Mark the models other projects may use as public:
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
models:
|
|
56
|
+
- name: dim_customers
|
|
57
|
+
config:
|
|
58
|
+
access: public
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
2. Add a step after `dbt build` in the producer's job:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
dbt build
|
|
65
|
+
xref publish --env prod --store s3://my-bucket/xref
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This reads `target/manifest.json` and writes
|
|
69
|
+
`s3://my-bucket/xref/<project>/prod/manifest.json`. Only public models are
|
|
70
|
+
published: their warehouse relation, description, columns and versions. SQL
|
|
71
|
+
and private models stay in the producer.
|
|
72
|
+
|
|
73
|
+
Publish from every environment consumers should read, for example a staging
|
|
74
|
+
job with `--env staging`.
|
|
75
|
+
|
|
76
|
+
## Consumer: sync before deps
|
|
77
|
+
|
|
78
|
+
1. Add `xref.yml` next to `dbt_project.yml`:
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
store: s3://my-bucket/xref
|
|
82
|
+
projects:
|
|
83
|
+
- core_platform
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. Add `.xref/` to `.gitignore`.
|
|
87
|
+
|
|
88
|
+
3. Run sync before dbt, locally and in the job:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
xref sync --env prod
|
|
92
|
+
dbt deps
|
|
93
|
+
dbt build
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The first sync adds `- local: .xref/core_platform` to `packages.yml` (or to
|
|
97
|
+
`dependencies.yml` if that is where your packages are), keeping your comments.
|
|
98
|
+
|
|
99
|
+
4. Reference upstream models:
|
|
100
|
+
|
|
101
|
+
```sql
|
|
102
|
+
select * from {{ ref('core_platform', 'dim_customers') }}
|
|
103
|
+
select * from {{ ref('core_platform', 'dim_customers', v=1) }} -- versioned
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The consumer's warehouse credentials need read access to the producer's tables.
|
|
107
|
+
|
|
108
|
+
## Environments
|
|
109
|
+
|
|
110
|
+
`--env` (or `$XREF_ENV`, default `prod`) names the environment you are running
|
|
111
|
+
in. By default `prod` reads the producer's `prod` manifest, and any other
|
|
112
|
+
environment reads its own name first, then falls back to `prod`. So `xref sync
|
|
113
|
+
--env dev` uses the producer's `dev` manifest if one is published, otherwise
|
|
114
|
+
production. Override per environment or pin a project:
|
|
115
|
+
|
|
116
|
+
```yaml
|
|
117
|
+
store: s3://my-bucket/xref
|
|
118
|
+
projects:
|
|
119
|
+
- core_platform
|
|
120
|
+
- name: finance
|
|
121
|
+
environment: prod # always read finance's production tables
|
|
122
|
+
environments:
|
|
123
|
+
dev: [staging, prod] # dev reads staging, then prod
|
|
124
|
+
ci: [staging, prod]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Configuration reference
|
|
128
|
+
|
|
129
|
+
| Setting | Where | Default |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| Store URL | `--store`, `$XREF_STORE`, `store:` in `xref.yml` (first wins) | none, required |
|
|
132
|
+
| Environment | `--env`, `$XREF_ENV` | `prod` |
|
|
133
|
+
| Upstream projects | `projects:` in `xref.yml` | none |
|
|
134
|
+
| Environment routing | `environments:` in `xref.yml` | see above |
|
|
135
|
+
| Stub package folder | `mesh_dir:` in `xref.yml` | `.xref` |
|
|
136
|
+
| Manifest path (publish) | `--manifest` | `target/manifest.json` |
|
|
137
|
+
|
|
138
|
+
A store is a URL (`s3://`, `gs://`, `az://`, or any fsspec URL) or a directory
|
|
139
|
+
path. Relative paths resolve against `--project-dir`. Publishing needs write
|
|
140
|
+
access (on S3, `s3:PutObject`), syncing needs read access (`s3:GetObject`).
|
|
141
|
+
Cloud credentials come from the usual places: on S3, the standard AWS
|
|
142
|
+
environment variables, profile or instance role.
|
|
143
|
+
|
|
144
|
+
## Limitations
|
|
145
|
+
|
|
146
|
+
- **Contracts are not enforced across projects.** dbt does not enforce
|
|
147
|
+
contracts on ephemeral models, so if the producer renames a column, the
|
|
148
|
+
consumer fails when the query runs. On the proprietary `dbt`, run
|
|
149
|
+
`dbt compile --static-analysis strict` in CI to catch it at compile time; it
|
|
150
|
+
checks against the live warehouse schema.
|
|
151
|
+
- **Data tests stay with the producer.** Stubs carry no tests, so producer
|
|
152
|
+
tests do not rerun in every consumer.
|
|
153
|
+
- **`projects:` in `dependencies.yml` does nothing** without the dbt platform.
|
|
154
|
+
xref uses a `local:` package entry instead.
|
|
155
|
+
- Only dbt manifest schema v12 is supported (dbt v2 and recent dbt 1.x write it).
|
|
156
|
+
- **Tested so far:** dbt v2.0.11 (`dbt-oss` and `dbt`) with DuckDB, and the S3
|
|
157
|
+
store against a local S3 server (moto). Stubs use the `relation_name` the
|
|
158
|
+
producer's own manifest records, so quoting follows the warehouse, but
|
|
159
|
+
Snowflake, BigQuery, Databricks and Redshift have not been run end to end.
|
|
160
|
+
GCS and Azure go through the same fsspec code as S3 and are untested.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
Apache 2.0. See [LICENSE](LICENSE).
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
uv sync
|
|
170
|
+
uv run pytest -m "not dbt" # unit tests
|
|
171
|
+
uv run pytest -m dbt # end to end against dbt and DuckDB
|
|
172
|
+
XREF_DBT="uvx --from dbt==2.0.11 dbt" uv run pytest -m dbt # proprietary dbt
|
|
173
|
+
uv run ruff check . && uv run pyright
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`spike/` holds the Phase 0 experiments that proved the design; see
|
|
177
|
+
[spike/FINDINGS.md](spike/FINDINGS.md).
|
|
178
|
+
|
|
179
|
+
To release, set `version` in `pyproject.toml`, merge to `master`, then push a
|
|
180
|
+
matching tag (`v0.1.0` for version `0.1.0`). The Publish workflow uploads to
|
|
181
|
+
PyPI through trusted publishing, in the `pypi` GitHub environment.
|
xref-0.1.0/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# xref
|
|
2
|
+
|
|
3
|
+
Cross-project `ref('project', 'model')` for dbt v2, without a dbt platform plan.
|
|
4
|
+
|
|
5
|
+
A producer project publishes a slim copy of its manifest after each run. A
|
|
6
|
+
consumer project syncs it before `dbt deps`, and xref writes a local dbt package
|
|
7
|
+
with one ephemeral stub per public model:
|
|
8
|
+
|
|
9
|
+
```sql
|
|
10
|
+
-- .xref/core_platform/models/dim_customers.sql (generated)
|
|
11
|
+
{{ config(materialized='ephemeral') }}
|
|
12
|
+
select * from "analytics"."core"."dim_customers"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
dbt then resolves `{{ ref('core_platform', 'dim_customers') }}` as an ordinary
|
|
16
|
+
package ref. It compiles to a CTE over the producer's table, lineage shows the
|
|
17
|
+
upstream model, and `dbt build` skips the stubs (`no-op`), so nothing upstream
|
|
18
|
+
is rebuilt. Tested on dbt v2.0.11, both `dbt-oss` and the proprietary `dbt`.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
xref is not on PyPI yet. Install from GitHub, with the extra for your store:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install "xref[s3] @ git+https://github.com/dietofworms/xref"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Extras: `s3` (S3 and S3-compatible), `gcs` (Google Cloud Storage), `azure`
|
|
29
|
+
(Azure Blob / ADLS). A local or network directory needs no extra.
|
|
30
|
+
|
|
31
|
+
## Producer: publish after each run
|
|
32
|
+
|
|
33
|
+
1. Mark the models other projects may use as public:
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
models:
|
|
37
|
+
- name: dim_customers
|
|
38
|
+
config:
|
|
39
|
+
access: public
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. Add a step after `dbt build` in the producer's job:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
dbt build
|
|
46
|
+
xref publish --env prod --store s3://my-bucket/xref
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This reads `target/manifest.json` and writes
|
|
50
|
+
`s3://my-bucket/xref/<project>/prod/manifest.json`. Only public models are
|
|
51
|
+
published: their warehouse relation, description, columns and versions. SQL
|
|
52
|
+
and private models stay in the producer.
|
|
53
|
+
|
|
54
|
+
Publish from every environment consumers should read, for example a staging
|
|
55
|
+
job with `--env staging`.
|
|
56
|
+
|
|
57
|
+
## Consumer: sync before deps
|
|
58
|
+
|
|
59
|
+
1. Add `xref.yml` next to `dbt_project.yml`:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
store: s3://my-bucket/xref
|
|
63
|
+
projects:
|
|
64
|
+
- core_platform
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
2. Add `.xref/` to `.gitignore`.
|
|
68
|
+
|
|
69
|
+
3. Run sync before dbt, locally and in the job:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
xref sync --env prod
|
|
73
|
+
dbt deps
|
|
74
|
+
dbt build
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The first sync adds `- local: .xref/core_platform` to `packages.yml` (or to
|
|
78
|
+
`dependencies.yml` if that is where your packages are), keeping your comments.
|
|
79
|
+
|
|
80
|
+
4. Reference upstream models:
|
|
81
|
+
|
|
82
|
+
```sql
|
|
83
|
+
select * from {{ ref('core_platform', 'dim_customers') }}
|
|
84
|
+
select * from {{ ref('core_platform', 'dim_customers', v=1) }} -- versioned
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The consumer's warehouse credentials need read access to the producer's tables.
|
|
88
|
+
|
|
89
|
+
## Environments
|
|
90
|
+
|
|
91
|
+
`--env` (or `$XREF_ENV`, default `prod`) names the environment you are running
|
|
92
|
+
in. By default `prod` reads the producer's `prod` manifest, and any other
|
|
93
|
+
environment reads its own name first, then falls back to `prod`. So `xref sync
|
|
94
|
+
--env dev` uses the producer's `dev` manifest if one is published, otherwise
|
|
95
|
+
production. Override per environment or pin a project:
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
store: s3://my-bucket/xref
|
|
99
|
+
projects:
|
|
100
|
+
- core_platform
|
|
101
|
+
- name: finance
|
|
102
|
+
environment: prod # always read finance's production tables
|
|
103
|
+
environments:
|
|
104
|
+
dev: [staging, prod] # dev reads staging, then prod
|
|
105
|
+
ci: [staging, prod]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Configuration reference
|
|
109
|
+
|
|
110
|
+
| Setting | Where | Default |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| Store URL | `--store`, `$XREF_STORE`, `store:` in `xref.yml` (first wins) | none, required |
|
|
113
|
+
| Environment | `--env`, `$XREF_ENV` | `prod` |
|
|
114
|
+
| Upstream projects | `projects:` in `xref.yml` | none |
|
|
115
|
+
| Environment routing | `environments:` in `xref.yml` | see above |
|
|
116
|
+
| Stub package folder | `mesh_dir:` in `xref.yml` | `.xref` |
|
|
117
|
+
| Manifest path (publish) | `--manifest` | `target/manifest.json` |
|
|
118
|
+
|
|
119
|
+
A store is a URL (`s3://`, `gs://`, `az://`, or any fsspec URL) or a directory
|
|
120
|
+
path. Relative paths resolve against `--project-dir`. Publishing needs write
|
|
121
|
+
access (on S3, `s3:PutObject`), syncing needs read access (`s3:GetObject`).
|
|
122
|
+
Cloud credentials come from the usual places: on S3, the standard AWS
|
|
123
|
+
environment variables, profile or instance role.
|
|
124
|
+
|
|
125
|
+
## Limitations
|
|
126
|
+
|
|
127
|
+
- **Contracts are not enforced across projects.** dbt does not enforce
|
|
128
|
+
contracts on ephemeral models, so if the producer renames a column, the
|
|
129
|
+
consumer fails when the query runs. On the proprietary `dbt`, run
|
|
130
|
+
`dbt compile --static-analysis strict` in CI to catch it at compile time; it
|
|
131
|
+
checks against the live warehouse schema.
|
|
132
|
+
- **Data tests stay with the producer.** Stubs carry no tests, so producer
|
|
133
|
+
tests do not rerun in every consumer.
|
|
134
|
+
- **`projects:` in `dependencies.yml` does nothing** without the dbt platform.
|
|
135
|
+
xref uses a `local:` package entry instead.
|
|
136
|
+
- Only dbt manifest schema v12 is supported (dbt v2 and recent dbt 1.x write it).
|
|
137
|
+
- **Tested so far:** dbt v2.0.11 (`dbt-oss` and `dbt`) with DuckDB, and the S3
|
|
138
|
+
store against a local S3 server (moto). Stubs use the `relation_name` the
|
|
139
|
+
producer's own manifest records, so quoting follows the warehouse, but
|
|
140
|
+
Snowflake, BigQuery, Databricks and Redshift have not been run end to end.
|
|
141
|
+
GCS and Azure go through the same fsspec code as S3 and are untested.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Apache 2.0. See [LICENSE](LICENSE).
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
uv sync
|
|
151
|
+
uv run pytest -m "not dbt" # unit tests
|
|
152
|
+
uv run pytest -m dbt # end to end against dbt and DuckDB
|
|
153
|
+
XREF_DBT="uvx --from dbt==2.0.11 dbt" uv run pytest -m dbt # proprietary dbt
|
|
154
|
+
uv run ruff check . && uv run pyright
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`spike/` holds the Phase 0 experiments that proved the design; see
|
|
158
|
+
[spike/FINDINGS.md](spike/FINDINGS.md).
|
|
159
|
+
|
|
160
|
+
To release, set `version` in `pyproject.toml`, merge to `master`, then push a
|
|
161
|
+
matching tag (`v0.1.0` for version `0.1.0`). The Publish workflow uploads to
|
|
162
|
+
PyPI through trusted publishing, in the `pypi` GitHub environment.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "xref"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Cross-project refs for dbt v2 without the dbt platform."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"fsspec>=2024.6",
|
|
11
|
+
"pydantic>=2.14.3",
|
|
12
|
+
"pyyaml>=6",
|
|
13
|
+
"typer>=0.29.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
xref = "xref.cli:app"
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
s3 = ["s3fs>=2026.9.0"]
|
|
21
|
+
gcs = ["gcsfs>=2026.10.1"]
|
|
22
|
+
azure = ["adlfs>=2026.8.0"]
|
|
23
|
+
|
|
24
|
+
[dependency-groups]
|
|
25
|
+
dev = [
|
|
26
|
+
"boto3>=1.43.117",
|
|
27
|
+
"boto3-stubs[s3]>=1.44.5",
|
|
28
|
+
"dbt-oss==2.0.11",
|
|
29
|
+
"duckdb>=2.0.0",
|
|
30
|
+
"moto[server]>=5.2.5",
|
|
31
|
+
"pyright>=1.1.414",
|
|
32
|
+
"pytest>=9.2.0",
|
|
33
|
+
"ruff>=0.17.4",
|
|
34
|
+
"s3fs>=2026.9.0",
|
|
35
|
+
"types-pyyaml>=6.0.12.20261113",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["uv-build>0.11,<0.12"]
|
|
40
|
+
build-backend = "uv_build"
|
|
41
|
+
|
|
42
|
+
[tool.pyright]
|
|
43
|
+
typeCheckingMode = "strict"
|
|
44
|
+
include = [
|
|
45
|
+
"src",
|
|
46
|
+
"tests",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
line-length = 100
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint]
|
|
53
|
+
select = [
|
|
54
|
+
"E",
|
|
55
|
+
"F",
|
|
56
|
+
"I",
|
|
57
|
+
"B",
|
|
58
|
+
"UP",
|
|
59
|
+
"SIM",
|
|
60
|
+
"RUF",
|
|
61
|
+
]
|
|
62
|
+
ignore = ["E501"]
|
|
63
|
+
|
|
64
|
+
[tool.pytest.ini_options]
|
|
65
|
+
testpaths = ["tests"]
|
|
66
|
+
markers = ["dbt: runs real dbt builds against DuckDB (slow, needs the dbt driver download)"]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "xref"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Cross-project refs for dbt v2 without the dbt platform."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"fsspec>=2024.6",
|
|
11
|
+
"pydantic>=2.14.3",
|
|
12
|
+
"pyyaml>=6",
|
|
13
|
+
"typer>=0.29.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"boto3>=1.43.117",
|
|
19
|
+
"boto3-stubs[s3]>=1.44.5",
|
|
20
|
+
"dbt-oss==2.0.11",
|
|
21
|
+
"duckdb>=2.0.0",
|
|
22
|
+
"moto[server]>=5.2.5",
|
|
23
|
+
"pyright>=1.1.414",
|
|
24
|
+
"pytest>=9.2.0",
|
|
25
|
+
"ruff>=0.17.4",
|
|
26
|
+
"s3fs>=2026.9.0",
|
|
27
|
+
"types-pyyaml>=6.0.12.20261113",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv-build>0.11,<0.12"]
|
|
32
|
+
build-backend = "uv_build"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
xref = "xref.cli:app"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
s3 = [
|
|
39
|
+
"s3fs>=2026.9.0",
|
|
40
|
+
]
|
|
41
|
+
gcs = [
|
|
42
|
+
"gcsfs>=2026.10.1",
|
|
43
|
+
]
|
|
44
|
+
azure = [
|
|
45
|
+
"adlfs>=2026.8.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[tool.pyright]
|
|
49
|
+
typeCheckingMode = "strict"
|
|
50
|
+
include = ["src", "tests"]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 100
|
|
54
|
+
|
|
55
|
+
[tool.ruff.lint]
|
|
56
|
+
select = ["E", "F", "I", "B", "UP", "SIM", "RUF"]
|
|
57
|
+
ignore = ["E501"] # the formatter wraps code; long messages stay on one line
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
61
|
+
markers = ["dbt: runs real dbt builds against DuckDB (slow, needs the dbt driver download)"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Narrow untyped JSON and YAML values to concrete types."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, cast
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def as_mapping(value: object) -> dict[str, Any] | None:
|
|
9
|
+
return cast(dict[str, Any], value) if isinstance(value, dict) else None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def as_list(value: object) -> list[Any] | None:
|
|
13
|
+
return cast(list[Any], value) if isinstance(value, list) else None
|