Skip to content

Commit 9b79092

Browse files
authored
Merge pull request #101 from dpguthrie/feat/use-beta-endpoint
Update Metadata Interface
2 parents daf8f15 + b8fff80 commit 9b79092

19 files changed

+1258
-13759
lines changed

.github/workflows/build.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
name: Build
22

33
on:
4-
pull_request_target:
5-
branches: [ main ]
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
- ready_for_review
612

713
jobs:
814
build:
915

1016
runs-on: ubuntu-latest
1117

1218
steps:
13-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
1420
- name: Set up Python 3.9
15-
uses: actions/setup-python@v2
21+
uses: actions/setup-python@v3
1622
with:
1723
python-version: "3.9"
1824
- name: Install dependencies

.isort.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import_heading_future=future
44
import_heading_local=local
55
import_heading_stdlib=stdlib
66
import_heading_thirdparty=third party
7-
known_third_party=sgqlc
87

98
# These settings makes isort compatible with Black:
109
# https://github.com/psf/black#how-black-wraps-lines

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
- id: mypy
2020
stages: [commit,push]
2121
name: mypy
22-
entry: poetry run mypy --ignore-missing-imports
22+
entry: poetry run mypy --ignore-missing-imports --follow-imports=skip --strict-optional
2323
language: system
2424
types: [python]
2525
- repo: https://github.com/pre-commit/pre-commit-hooks

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## [0.9.0] - 2024-01-11
4+
5+
### Removed
6+
7+
- All of the methods in the `_MetadataClient` except for `query`. The Discovery API no longer allows a user to specify every single field recursively, which is what the `sgqlc` package would do.
8+
9+
### Added
10+
11+
- An optional keyword argument `use_beta_endpoint` to the `dbtCloudClient` class. This will default to `True`, which means that the Discovery API will use the beta endpoint at https://metadata.<host>/beta/graphql instead of https://metadata.<host>/graphql. This contains both the stable API resources (environment, models, tests, etc.) but also contains things for performance, recommendations, and lineage.
12+
- Ability to automatically paginate requests for the Discovery API. If pagination is required/desired, ensure that your query is properly created with an `$after` variable and all of the fields within the `pageInfo` field.
13+
14+
### Updated
15+
16+
- Loosen restrictions on Pydantic - ">=2.0,<3.0"
17+
18+
## [0.8.1] - 2023-12-20
19+
20+
### Updated
21+
22+
- Pydantic version from 1.10.5 to 2.5.*
23+
324
## [0.8.0] - 2023-12-04
425

526
### Added

README.md

+37-11
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,50 @@ run['data']
8383
run['status']
8484
```
8585

86-
Similarly, use the `metadata` property to retrieve information about certain resources within your project - the example below shows how to retrieve metadata from models related to the most recent run for a given `job_id`.
86+
Similarly, use the `metadata` property to retrieve information from the [Discovery API](https://docs.getdbt.com/docs/dbt-cloud-apis/discovery-api).
87+
Here's how you could retrieve all of the metrics for your project.
8788

8889
```python
8990
from dbtc import dbtCloudClient
9091

9192
client = dbtCloudClient()
92-
93-
job_id = 1
94-
95-
models = client.metadata.get_models(job_id)
96-
97-
# Models nested inside a couple keys
98-
models['data']['models']
99-
100-
# This is a list
101-
models['data']['models'][0]
93+
query = '''
94+
query ($environmentId: BigInt!, $first: Int!) {
95+
environment(id: $environmentId) {
96+
definition {
97+
metrics(first: $first) {
98+
edges {
99+
node {
100+
name
101+
description
102+
type
103+
formula
104+
filter
105+
tags
106+
parents {
107+
name
108+
resourceType
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}
116+
'''
117+
variables = {'environmentId': 1, 'first': 500}
118+
data = client.metadata.query(query, variables)
119+
120+
# Data will be in the edges key, which will be a list of nodes
121+
nodes = data['data']['definition']['metrics']['edges']
122+
for node in nodes:
123+
# node is a dictionary
124+
node_name = node['name']
125+
...
102126
```
103127

128+
If you're unfamiliar either with the Schema to query or even how to write a GraphQL query, I highly recommend going to the [dbt Cloud Discovery API playground](https://metadata.cloud.getdbt.com/beta/graphql). You'll be able to interactively explore the Schema while watching it write a GraphQL query for you!
129+
104130
### CLI
105131

106132
The CLI example below will map to the python cloud example above:

dbtc/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.0"
1+
__version__ = "0.9.0"

0 commit comments

Comments
 (0)