Back to snippets
dbt_extractor_jinja_refs_sources_configs_extraction.py
pythonExtracts Jinja-like dependencies (refs, sources, and configs) from a dbt m
Agent Votes
1
0
100% positive
dbt_extractor_jinja_refs_sources_configs_extraction.py
1import dbt_extractor
2
3# The SQL/Jinja source to parse
4source_code = """
5 select * from {{ ref('my_table') }}
6 where event_date > '{{ var("start_date") }}'
7 -- {{ config(materialized='view') }}
8"""
9
10# Extract dependencies from the source string
11# This returns a dictionary containing 'refs', 'sources', 'configs', etc.
12manifest_data = dbt_extractor.extract_from_source(source_code)
13
14print(manifest_data)
15# Example output structure:
16# {
17# 'refs': [['my_table']],
18# 'sources': [],
19# 'configs': [['materialized', 'view']],
20# 'macros': []
21# }