Skip to main content

An unaffiliated python interface for dbt Cloud APIs

Coverage Package version Downloads


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.

Release files for dbtc 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbtc 0.5.3
File Size Uploaded
dbtc-0.5.3.tar.gz 41.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbtc 0.5.3
File Interpreter ABI Platform
dbtc-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 85.8 kB

Release files / dbtc-0.5.3.tar.gz

Download URL dbtc-0.5.3.tar.gz
Size 41.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ed3f30af386e02eb331c78907899f20e089f4f46a1a4dda564cceab6b9f92598
BLAKE2b-256 checksum
How to use checksums
8f474e67cec3054a82a4f758ae8655c437e40d2d756c9beaf72d3442688fc5c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1042-azure

Release files / dbtc-0.5.3-py3-none-any.whl

Download URL dbtc-0.5.3-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dab616190196e5df1c1165ecd147e066c9258151d5582cbaa21bda3ca6177fde
BLAKE2b-256 checksum
How to use checksums
6b6760f7beaaaa6c14a8b778f83f9405f1b7b39f585f0e32187e0644357ffb9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1042-azure

Release history Release notifications | RSS feed

0.11.6

2 release files

0.11.5

2 release files

0.11.3

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

This release

0.5.3 This release

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page