dbtc


Namedbtc JSON
Version 0.11.2 PyPI version JSON
download
home_pageNone
SummaryAn unaffiliated python wrapper for dbt Cloud APIs
upload_time2024-04-06 14:06:05
maintainerNone
docs_urlNone
authorDoug Guthrie
requires_python<4.0,>=3.8
licenseMIT
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://dpguthrie-dbtc-streamlit-home-yy7c0b.streamlit.app/">https://dpguthrie-dbtc-streamlit-home-yy7c0b.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/ce/c4/74682563e1cbae29e02b4015c498e7e796f7e4803c069b944329ac356fac/dbtc-0.11.2.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://dpguthrie-dbtc-streamlit-home-yy7c0b.streamlit.app/\">https://dpguthrie-dbtc-streamlit-home-yy7c0b.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.2",
    "project_urls": {
        "Documentation": "https://dbtc.dpguthrie.com"
    },
    "split_keywords": [
        "dbt",
        " requests",
        " api",
        " dbt cloud"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e07489afac0548e8367b0f4ad5eada7d52a92220dcdea6432de290fb545c755",
                "md5": "0a34f1e4eab1b474fef864ca3144a2d5",
                "sha256": "e716dbe89f2e2c5a68263cbf82d296aefd1ca83c44178e53b7f7a837b6e6f878"
            },
            "downloads": -1,
            "filename": "dbtc-0.11.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0a34f1e4eab1b474fef864ca3144a2d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 34852,
            "upload_time": "2024-04-06T14:06:04",
            "upload_time_iso_8601": "2024-04-06T14:06:04.243861Z",
            "url": "https://files.pythonhosted.org/packages/5e/07/489afac0548e8367b0f4ad5eada7d52a92220dcdea6432de290fb545c755/dbtc-0.11.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cec474682563e1cbae29e02b4015c498e7e796f7e4803c069b944329ac356fac",
                "md5": "8834763759e68e46bbb2204066b8b905",
                "sha256": "d6a7cf812acbf37a3e9720ee3f5d0fdbfdf7db1d0ebfd8db4f356fb960c8f54b"
            },
            "downloads": -1,
            "filename": "dbtc-0.11.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8834763759e68e46bbb2204066b8b905",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 32793,
            "upload_time": "2024-04-06T14:06:05",
            "upload_time_iso_8601": "2024-04-06T14:06:05.763871Z",
            "url": "https://files.pythonhosted.org/packages/ce/c4/74682563e1cbae29e02b4015c498e7e796f7e4803c069b944329ac356fac/dbtc-0.11.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-06 14:06:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "dbtc"
}
        
Elapsed time: 0.30801s