Bases: BaseModel
Root configuration for dbt-contracts.
Loaded from contracts/config.yaml in a dbt project.
Source code in src/dbt_contracts/models/config.py
| class Config(pyd.BaseModel):
"""Root configuration for dbt-contracts.
Loaded from ``contracts/config.yaml`` in a dbt project.
"""
model_config = pyd.ConfigDict(extra="forbid")
project_name: str | None = None
dbt_project_dir: str | None = ".."
default_server_type: str | None = "snowflake"
generation: GenerationConfig | None = None
validation: ValidationConfig | None = None
@classmethod
def from_file(cls, file_path: str) -> "Config":
"""Load configuration from a YAML file."""
with open(file_path, encoding="utf-8") as f:
content = f.read()
return cls.from_string(content)
@classmethod
def from_string(cls, config_str: str) -> "Config":
"""Load configuration from a YAML string."""
data = yaml.safe_load(config_str) or {}
return cls(**data)
def to_yaml(self) -> str:
"""Serialize configuration to a YAML string."""
return yaml.dump(
self.model_dump(exclude_defaults=True, exclude_none=True, by_alias=True),
sort_keys=False,
allow_unicode=True,
)
|
from_file(file_path)
classmethod
Load configuration from a YAML file.
Source code in src/dbt_contracts/models/config.py
| @classmethod
def from_file(cls, file_path: str) -> "Config":
"""Load configuration from a YAML file."""
with open(file_path, encoding="utf-8") as f:
content = f.read()
return cls.from_string(content)
|
from_string(config_str)
classmethod
Load configuration from a YAML string.
Source code in src/dbt_contracts/models/config.py
| @classmethod
def from_string(cls, config_str: str) -> "Config":
"""Load configuration from a YAML string."""
data = yaml.safe_load(config_str) or {}
return cls(**data)
|
to_yaml()
Serialize configuration to a YAML string.
Source code in src/dbt_contracts/models/config.py
| def to_yaml(self) -> str:
"""Serialize configuration to a YAML string."""
return yaml.dump(
self.model_dump(exclude_defaults=True, exclude_none=True, by_alias=True),
sort_keys=False,
allow_unicode=True,
)
|