Skip to main content

An unaffiliated python wrapper for dbt Cloud APIs

Project description

An unaffiliated python interface for dbt Cloud APIs

Coverage Package version Downloads


Documentation: https://dbtc.dpguthrie.com

Source Code: https://github.com/dpguthrie/dbtc

V2 Docs: https://docs.getdbt.com/dbt-cloud/api-v2

V3 Docs (Unofficial): https://documenter.getpostman.com/view/14183654/UVsSNiXC

V4 Docs: https://docs.getdbt.com/dbt-cloud/api-v4


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, that with certain arguments, allows you to restart a job from the 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(
    account_id,
    job_id,
    payload,
    restart_from_failure=True,
    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 \
    --account-id 1
    --job-id 1
    --payload '{"cause": "Restarting from failure"}' \
    --restart_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbtc-0.2.3.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

dbtc-0.2.3-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file dbtc-0.2.3.tar.gz.

File metadata

  • Download URL: dbtc-0.2.3.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for dbtc-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6cbcab941c79e2145ca5f9263612d7f3407834215d8ac9295da8f89c54d35562
MD5 b64b06a2b6c7e4db986cc715ffd5f9df
BLAKE2b-256 e6ac1c85e7b447bfb3fa796d1d0651e322062268c7ad4a9bfb6d329744d915c1

See more details on using hashes here.

File details

Details for the file dbtc-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: dbtc-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for dbtc-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ded4a60acbdb2126a222218a92924de824a216b2d173bb0cf0b50a500623232d
MD5 f4e5e904f6fec0071217a28393e1e7c3
BLAKE2b-256 b92f638a2caca2ec26d100e27b28634ffc6bcaf8e570edb8956ac9ca383e0cac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page