{"id":13703192,"url":"https://github.com/dpguthrie/dbtc","last_synced_at":"2025-04-05T02:12:29.639Z","repository":{"id":40286759,"uuid":"457570824","full_name":"dpguthrie/dbtc","owner":"dpguthrie","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-28T15:49:47.000Z","size":2859,"stargazers_count":40,"open_issues_count":8,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T01:14:51.567Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpguthrie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-10T00:08:13.000Z","updated_at":"2025-02-28T21:00:27.000Z","dependencies_parsed_at":"2024-04-17T04:35:01.189Z","dependency_job_id":"2deb8c4a-8b8c-453e-9f6e-c3912d32bb05","html_url":"https://github.com/dpguthrie/dbtc","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbtc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbtc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbtc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbtc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpguthrie","download_url":"https://codeload.github.com/dpguthrie/dbtc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T21:00:51.609Z","updated_at":"2025-04-05T02:12:29.622Z","avatar_url":"https://github.com/dpguthrie.png","language":"Python","funding_links":[],"categories":["Utilities"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"#\"\u003e\u003cimg src=\"docs/img/dbt-standalone.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eAn unaffiliated python interface for dbt Cloud APIs\u003c/em\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://codecov.io/gh/dpguthrie/dbtc\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/codecov/c/github/dpguthrie/dbtc\" alt=\"Coverage\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/dbtc\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://badge.fury.io/py/dbtc.svg\" alt=\"Package version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pepy.tech/project/dbtc\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://pepy.tech/badge/dbtc\" alt=\"Downloads\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Documentation**: \u003ca target=\"_blank\" href=\"https://dbtc.dpguthrie.com\"\u003ehttps://dbtc.dpguthrie.com\u003c/a\u003e\n\n**Interactive Demo**: \u003ca target=\"_blank\" href=\"https://dbtc-python.streamlit.app/\"\u003ehttps://dbtc-python.streamlit.app/\u003c/a\u003e\n\n**Source Code**: \u003ca target=\"_blank\" href=\"https://github.com/dpguthrie/dbtc\"\u003ehttps://github.com/dpguthrie/dbtc\u003c/a\u003e\n\n**V2 Docs**: \u003ca target=\"_blank\" href=\"https://docs.getdbt.com/dbt-cloud/api-v2\"\u003ehttps://docs.getdbt.com/dbt-cloud/api-v2\u003c/a\u003e\n\n**V3 Docs**: \u003ca target=\"_blank\" href=\"https://docs.getdbt.com/dbt-cloud/api-v3\"\u003ehttps://docs.getdbt.com/dbt-cloud/api-v3\u003c/a\u003e\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\n    resources 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.8+\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\nOr better yet, use [uv](https://docs.astral.sh/uv/)\n\n```bash\nuv pip install dbtc\n```\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpguthrie%2Fdbtc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpguthrie%2Fdbtc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpguthrie%2Fdbtc/lists"}