Skip to content

dbt Models

prefect_dbt_flow.dbt

Code for managing and configuring a dbt project.

DbtDagOptions dataclass

Class to add dbt DAG configurations.

Parameters:

Name Type Description Default
select Optional[str]

dbt module to include in the run

None
exclude Optional[str]

dbt module to exclude in the run

None
run_test_after_model bool

run test afeter run model

False
vars Optional[dict[str, str]]

dbt vars

None
install_deps bool

install dbt dependencies, default behavior install deps

True
Source code in prefect_dbt_flow/dbt/__init__.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@dataclass
class DbtDagOptions:
    """
    Class to add dbt DAG configurations.

    Args:
        select: dbt module to include in the run
        exclude: dbt module to exclude in the run
        run_test_after_model: run test afeter run model
        vars: dbt vars
        install_deps: install dbt dependencies, default behavior install deps
    """

    select: Optional[str] = None
    exclude: Optional[str] = None
    run_test_after_model: bool = False
    vars: Optional[dict[str, str]] = None
    install_deps: bool = True

DbtNode dataclass

Class that represents a dbt node in the project.

Parameters:

Name Type Description Default
name str

dbt node name, e. my_model_a

required
unique_id str

dbt id e. model.sample_project.my_model_a

required
resource_type DbtResourceType

dbt resource type, e. model or seed

required
depends_on List[str]

e. ["model.sample_project.my_model_b"]

required
has_tests bool

if node is a test

False
Source code in prefect_dbt_flow/dbt/__init__.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@dataclass
class DbtNode:
    """
    Class that represents a dbt node in the project.

    Args:
        name: dbt node name, e. my_model_a
        unique_id: dbt id e. model.sample_project.my_model_a
        resource_type: dbt resource type, e. model or seed
        depends_on: e. ["model.sample_project.my_model_b"]
        has_tests: if node is a test
    """

    name: str
    unique_id: str
    resource_type: DbtResourceType
    depends_on: List[str]
    has_tests: bool = False

DbtProfile dataclass

Class that represents a dbt profile configuration.

Parameters:

Name Type Description Default
target str

dbt target, usualy "dev" or "prod"

required
overrides Optional[dict[str, str]]

dbt profile overrides

None
Source code in prefect_dbt_flow/dbt/__init__.py
34
35
36
37
38
39
40
41
42
43
44
45
@dataclass
class DbtProfile:
    """
    Class that represents a dbt profile configuration.

    Args:
        target: dbt target, usualy "dev" or "prod"
        overrides: dbt profile overrides
    """

    target: str
    overrides: Optional[dict[str, str]] = None

DbtProject dataclass

Class that represents a dbt project configuration.

Parameters:

Name Type Description Default
name str

Name of dbt project,

required
project_dir Union[str, Path]

Path to directory that contains dbt project.yml

required
profiles_dir Union[str, Path]

Path to directory that contains dbt profiles.yml

required
Source code in prefect_dbt_flow/dbt/__init__.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@dataclass
class DbtProject:
    """
    Class that represents a dbt project configuration.

    Args:
        name: Name of dbt project,
        project_dir: Path to directory that contains dbt project.yml
        profiles_dir: Path to directory that contains dbt profiles.yml
    """

    name: str
    project_dir: Union[str, Path]
    profiles_dir: Union[str, Path]

DbtResourceType

Bases: Enum

Enum class that represents a dbt resource type.

Source code in prefect_dbt_flow/dbt/__init__.py
 8
 9
10
11
12
13
14
15
class DbtResourceType(Enum):
    """
    Enum class that represents a dbt resource type.
    """

    MODEL = auto()
    SEED = auto()
    SNAPSHOT = auto()