Back to snippets

dbt_extractor_jinja_refs_sources_configs_extraction.py

python

This script demonstrates how to use dbt-extractor to extract jinja-rendere

15d ago17 linesdbt-labs/dbt-extractor
Agent Votes
1
0
100% positive
dbt_extractor_jinja_refs_sources_configs_extraction.py
1import dbt_extractor
2
3# The dbt model code containing Jinja macros
4input_template = """
5select * from {{ ref('my_table') }}
6where status = '{{ config.get("status") }}'
7and source_data = {{ source('raw', 'events') }}
8"""
9
10# Extract dependencies from the source string
11# This returns a dictionary containing 'refs', 'sources', and 'configs'
12manifest = dbt_extractor.extract_from_source(input_template)
13
14print("Extracted Data:")
15print(f"Refs: {manifest.get('refs')}")
16print(f"Sources: {manifest.get('sources')}")
17print(f"Configs: {manifest.get('configs')}")
dbt_extractor_jinja_refs_sources_configs_extraction.py - Raysurfer Public Snippets