Name | dbtc JSON |
Version |
0.11.4
JSON |
| download |
home_page | None |
Summary | An unaffiliated python wrapper for dbt Cloud APIs |
upload_time | 2024-09-04 16:38:49 |
maintainer | None |
docs_url | None |
author | Doug Guthrie |
requires_python | <4.0,>=3.8 |
license | MIT |
keywords |
dbt
requests
api
dbt cloud
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<a href="#"><img src="docs/img/dbt-standalone.png"></a>
</p>
<p align="center">
<em>An unaffiliated python interface for dbt Cloud APIs</em>
</p>
<p align="center">
<a href="https://codecov.io/gh/dpguthrie/dbtc" target="_blank">
<img src="https://img.shields.io/codecov/c/github/dpguthrie/dbtc" alt="Coverage">
</a>
<a href="https://pypi.org/project/dbtc" target="_blank">
<img src="https://badge.fury.io/py/dbtc.svg" alt="Package version">
</a>
<a href="https://pepy.tech/project/dbtc" target="_blank">
<img src="https://pepy.tech/badge/dbtc" alt="Downloads">
</a>
</p>
---
**Documentation**: <a target="_blank" href="https://dbtc.dpguthrie.com">https://dbtc.dpguthrie.com</a>
**Interactive Demo**: <a target="_blank" href="https://dbtc-python.streamlit.app/">https://dbtc-python.streamlit.app/</a>
**Source Code**: <a target="_blank" href="https://github.com/dpguthrie/dbtc">https://github.com/dpguthrie/dbtc</a>
**V2 Docs**: <a target="_blank" href="https://docs.getdbt.com/dbt-cloud/api-v2">https://docs.getdbt.com/dbt-cloud/api-v2</a>
**V3 Docs**: <a target="_blank" href="https://docs.getdbt.com/dbt-cloud/api-v3">https://docs.getdbt.com/dbt-cloud/api-v3</a>
---
## Overview
dbtc is an unaffiliated python interface to various dbt Cloud API endpoints.
This library acts as a convenient interface to two different APIs that dbt Cloud offers:
- Cloud API: This is a REST API that exposes endpoints that allow users to programatically create, read, update, and delete
resources within their dbt Cloud Account.
- Metadata API: This is a GraphQL API that exposes metadata generated from a job run within dbt Cloud.
## Requirements
Python 3.7+
- [Requests](https://requests.readthedocs.io/en/master/) - The elegant and simple HTTP library for Python, built for human beings.
- [sgqlc](https://github.com/profusion/sgqlc) - Simple GraphQL Client
- [Typer](https://github.com/tiangolo/typer) - Library for building CLI applications
## Installation
```bash
pip install dbtc
```
## Basic Usage
### Python
The interface to both APIs are located in the `dbtCloudClient` class.
The example below shows how you use the `cloud` property on an instance of the `dbtCloudClient` class to to access a method, `trigger_job_from_failure`, that allows you to restart a job from its last point of failure.
```python
from dbtc import dbtCloudClient
# Assumes that DBT_CLOUD_SERVICE_TOKEN env var is set
client = dbtCloudClient()
account_id = 1
job_id = 1
payload = {'cause': 'Restarting from failure'}
run = client.cloud.trigger_job_from_failure(
account_id,
job_id,
payload,
should_poll=False,
)
# This returns a dictionary containing two keys
run['data']
run['status']
```
Similarly, use the `metadata` property to retrieve information from the [Discovery API](https://docs.getdbt.com/docs/dbt-cloud-apis/discovery-api).
Here's how you could retrieve all of the metrics for your project.
```python
from dbtc import dbtCloudClient
client = dbtCloudClient()
query = '''
query ($environmentId: BigInt!, $first: Int!) {
environment(id: $environmentId) {
definition {
metrics(first: $first) {
edges {
node {
name
description
type
formula
filter
tags
parents {
name
resourceType
}
}
}
}
}
}
}
'''
variables = {'environmentId': 1, 'first': 500}
data = client.metadata.query(query, variables)
# Data will be in the edges key, which will be a list of nodes
nodes = data['data']['definition']['metrics']['edges']
for node in nodes:
# node is a dictionary
node_name = node['name']
...
```
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!
### CLI
The CLI example below will map to the python cloud example above:
```bash
dbtc trigger-job-from-failure \
--account-id 1 \
--job-id 1 \
--payload '{"cause": "Restarting from failure"}' \
--no-should-poll
```
Similarly, for the metadata example above (assuming that you've put both the `query` and `variables` argument into variables):
```bash
dbtc query --query $query --variables $variables
```
If not setting your service token as an environment variable, do the following:
```bash
dbtc --token this_is_my_token query --query $query --variables $variables
```
## License
This project is licensed under the terms of the MIT license.
Raw data
{
"_id": null,
"home_page": null,
"name": "dbtc",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "dbt, requests, API, dbt Cloud",
"author": "Doug Guthrie",
"author_email": "douglas.p.guthrie@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ea/1e/6ede261226a5ff355b4cfcc426ed15fa2262609da7c0efc114d1acc83a11/dbtc-0.11.4.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <a href=\"#\"><img src=\"docs/img/dbt-standalone.png\"></a>\n</p>\n<p align=\"center\">\n <em>An unaffiliated python interface for dbt Cloud APIs</em>\n</p>\n<p align=\"center\">\n <a href=\"https://codecov.io/gh/dpguthrie/dbtc\" target=\"_blank\">\n <img src=\"https://img.shields.io/codecov/c/github/dpguthrie/dbtc\" alt=\"Coverage\">\n </a>\n <a href=\"https://pypi.org/project/dbtc\" target=\"_blank\">\n <img src=\"https://badge.fury.io/py/dbtc.svg\" alt=\"Package version\">\n </a>\n <a href=\"https://pepy.tech/project/dbtc\" target=\"_blank\">\n <img src=\"https://pepy.tech/badge/dbtc\" alt=\"Downloads\">\n </a>\n</p>\n\n---\n\n**Documentation**: <a target=\"_blank\" href=\"https://dbtc.dpguthrie.com\">https://dbtc.dpguthrie.com</a>\n\n**Interactive Demo**: <a target=\"_blank\" href=\"https://dbtc-python.streamlit.app/\">https://dbtc-python.streamlit.app/</a>\n\n**Source Code**: <a target=\"_blank\" href=\"https://github.com/dpguthrie/dbtc\">https://github.com/dpguthrie/dbtc</a>\n\n**V2 Docs**: <a target=\"_blank\" href=\"https://docs.getdbt.com/dbt-cloud/api-v2\">https://docs.getdbt.com/dbt-cloud/api-v2</a>\n\n**V3 Docs**: <a target=\"_blank\" href=\"https://docs.getdbt.com/dbt-cloud/api-v3\">https://docs.getdbt.com/dbt-cloud/api-v3</a>\n\n---\n\n## Overview\n\ndbtc is an unaffiliated python interface to various dbt Cloud API endpoints.\n\nThis library acts as a convenient interface to two different APIs that dbt Cloud offers:\n\n- Cloud API: This is a REST API that exposes endpoints that allow users to programatically create, read, update, and delete\nresources within their dbt Cloud Account.\n- Metadata API: This is a GraphQL API that exposes metadata generated from a job run within dbt Cloud.\n\n## Requirements\n\nPython 3.7+\n\n- [Requests](https://requests.readthedocs.io/en/master/) - The elegant and simple HTTP library for Python, built for human beings.\n- [sgqlc](https://github.com/profusion/sgqlc) - Simple GraphQL Client\n- [Typer](https://github.com/tiangolo/typer) - Library for building CLI applications\n\n## Installation\n\n```bash\npip install dbtc\n```\n## Basic Usage\n\n### Python\n\nThe interface to both APIs are located in the `dbtCloudClient` class.\n\nThe example below shows how you use the `cloud` property on an instance of the `dbtCloudClient` class to to access a method, `trigger_job_from_failure`, that allows you to restart a job from its last point of failure.\n\n```python\nfrom dbtc import dbtCloudClient\n\n# Assumes that DBT_CLOUD_SERVICE_TOKEN env var is set\nclient = dbtCloudClient()\n\naccount_id = 1\njob_id = 1\npayload = {'cause': 'Restarting from failure'}\n\nrun = client.cloud.trigger_job_from_failure(\n account_id,\n job_id,\n payload,\n should_poll=False,\n)\n\n# This returns a dictionary containing two keys\nrun['data']\nrun['status']\n```\n\nSimilarly, use the `metadata` property to retrieve information from the [Discovery API](https://docs.getdbt.com/docs/dbt-cloud-apis/discovery-api).\nHere's how you could retrieve all of the metrics for your project.\n\n```python\nfrom dbtc import dbtCloudClient\n\nclient = dbtCloudClient()\nquery = '''\nquery ($environmentId: BigInt!, $first: Int!) {\n environment(id: $environmentId) {\n definition {\n metrics(first: $first) {\n edges {\n node {\n name\n description\n type\n formula\n filter\n tags\n parents {\n name\n resourceType\n }\n }\n }\n }\n }\n }\n}\n'''\nvariables = {'environmentId': 1, 'first': 500}\ndata = client.metadata.query(query, variables)\n\n# Data will be in the edges key, which will be a list of nodes\nnodes = data['data']['definition']['metrics']['edges']\nfor node in nodes:\n # node is a dictionary\n node_name = node['name']\n ...\n```\n\nIf 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!\n\n### CLI\n\nThe CLI example below will map to the python cloud example above:\n\n```bash\ndbtc trigger-job-from-failure \\\n --account-id 1 \\\n --job-id 1 \\\n --payload '{\"cause\": \"Restarting from failure\"}' \\\n --no-should-poll\n```\n\nSimilarly, for the metadata example above (assuming that you've put both the `query` and `variables` argument into variables):\n\n```bash\ndbtc query --query $query --variables $variables\n```\n\nIf not setting your service token as an environment variable, do the following:\n\n```bash\ndbtc --token this_is_my_token query --query $query --variables $variables\n```\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An unaffiliated python wrapper for dbt Cloud APIs",
"version": "0.11.4",
"project_urls": {
"Documentation": "https://dbtc.dpguthrie.com"
},
"split_keywords": [
"dbt",
" requests",
" api",
" dbt cloud"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "37ae4d99a91aff1c636d7a380bce0eba6cfc0df3375d0ed22e2b0db413ac50d3",
"md5": "ea990ad51e856c94a9c6a70053acc2b5",
"sha256": "730594597406dde8b373da8a493651878569e323c3df53cb895c84fa26995c1f"
},
"downloads": -1,
"filename": "dbtc-0.11.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ea990ad51e856c94a9c6a70053acc2b5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 34874,
"upload_time": "2024-09-04T16:38:47",
"upload_time_iso_8601": "2024-09-04T16:38:47.835082Z",
"url": "https://files.pythonhosted.org/packages/37/ae/4d99a91aff1c636d7a380bce0eba6cfc0df3375d0ed22e2b0db413ac50d3/dbtc-0.11.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ea1e6ede261226a5ff355b4cfcc426ed15fa2262609da7c0efc114d1acc83a11",
"md5": "5cb8467d99bd8f2354446f1ea945c701",
"sha256": "5a75c112633b9a26e4acfbbeb9c4b89e8b9c9f3b7625a9070cf1c092577209a4"
},
"downloads": -1,
"filename": "dbtc-0.11.4.tar.gz",
"has_sig": false,
"md5_digest": "5cb8467d99bd8f2354446f1ea945c701",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 32791,
"upload_time": "2024-09-04T16:38:49",
"upload_time_iso_8601": "2024-09-04T16:38:49.257544Z",
"url": "https://files.pythonhosted.org/packages/ea/1e/6ede261226a5ff355b4cfcc426ed15fa2262609da7c0efc114d1acc83a11/dbtc-0.11.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-04 16:38:49",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dbtc"
}