An unaffiliated python wrapper for dbt Cloud APIs
Project description
An unaffiliated python interface for dbt Cloud APIs
Documentation: https://dbtc.dpguthrie.com
Interactive Demo: https://dpguthrie-dbtc-streamlit-home-yy7c0b.streamlit.app/
Source Code: https://github.com/dpguthrie/dbtc
V2 Docs: https://docs.getdbt.com/dbt-cloud/api-v2
V3 Docs: https://docs.getdbt.com/dbt-cloud/api-v3
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 - The elegant and simple HTTP library for Python, built for human beings.
- sgqlc - Simple GraphQL Client
- Typer - Library for building CLI applications
Installation
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.
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 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
.
from dbtc import dbtCloudClient
client = dbtCloudClient()
job_id = 1
models = client.metadata.get_models(job_id)
# Models nested inside a couple keys
models['data']['models']
# This is a list
models['data']['models'][0]
CLI
The CLI example below will map to the python cloud example above:
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:
dbtc get-models --job-id 1
If not setting your service token as an environment variable, do the following:
dbtc --token this_is_my_token get_models --job-id 1
License
This project is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dbtc-0.5.2.tar.gz
.
File metadata
- Download URL: dbtc-0.5.2.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fe6894084bfe7a930ae11e21f0b0c59e7f0f3d77a1c1920728f73d46cc37a31 |
|
MD5 | fb7a6dad670b92e1893e259b6ddbe0df |
|
BLAKE2b-256 | 746cd09bb9b16e353e567aba3de23afbcf0f3aa1fda5ab217e2141a7fc2fab72 |
File details
Details for the file dbtc-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: dbtc-0.5.2-py3-none-any.whl
- Upload date:
- Size: 43.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28c72cfc0b8b25b8dce1571bcfedb4320c629ce97f3f548ecd4672e0dea94de4 |
|
MD5 | 4ddcc4740eb2c17df2e9107e8e3e8527 |
|
BLAKE2b-256 | b735b081b2e293c66f5165ba73b9cd1fe49b9433459f10447aef2fb36c8929d6 |