Skip to content

Instantly share code, notes, and snippets.

View b-per's full-sized avatar

Benoit Perigaud b-per

  • dbt Labs
  • Madrid, Spain
  • 02:10 (UTC +02:00)
View GitHub Profile
@b-per
b-per / retrieve_dependencies.py
Created September 27, 2022 15:37
Retrieve dependencies for all releases of dbt packages
# this script requires a github personal access token (PAT) with read repos scope
import requests
import os
s = requests.Session()
GITHUB_API_PAT = os.environ['GITHUB_API_PAT']
def get_releases(repo):
@b-per
b-per / dbt_cloud_api_vanilla_python.py
Last active March 19, 2024 16:55
Call dbt Cloud API to trigger jobs without having to install requests
from urllib.request import Request, urlopen
from urllib import parse
import os
import time
import json
#------------------------------------------------------------------------------
# get environment variables
#------------------------------------------------------------------------------
api_base = os.getenv('DBT_URL', 'https://cloud.getdbt.com/') # default to multitenant url
@b-per
b-per / README.MD
Created March 4, 2022 10:28
Python script to create a fake manifest to defer to locally

This script could be used locally when someone wants to build models in their own schema while deferring to the Prodcution models and not having the Production manifest file stored locally.

It creates a modified manifest.yml file based on a local one, changing the schema name from the local one to the Production one. The target_name argument is the name of the folder where the new manifest will be created. It defaults to target2 but can be updated

Usage: python build_defer_manifest.py [--target_name TARGET_NAME] dev_schema defer_schema

After having generated the manifest, you can do a dbt run -s <my_model> --defer --state target2

Notes:

@b-per
b-per / _dbt
Created August 16, 2020 09:07
ZSH completion script for dbt
#compdef dbt
# OVERVIEW
# Adds autocompletion to dbt CLI by:
# 1. Finding the root of the repo (identified by dbt_project.yml
# 2. Parsing target/manifest.json file, extracting valid model selectors
# 3. Doing some bash magic to autocomplete selectors for:
# -m
# --model[s]
# --exclude