Models¶
Pydantic models for koality configuration validation.
Config
pydantic-model
¶
Bases: BaseModel
Root configuration model for koality check execution.
Config:
extra:forbid
Fields:
-
name(str) -
extensions(list[ExtensionConfig]) -
extension_directory(str | None) -
database_setup(str) -
database_accessor(str) -
defaults(_GlobalDefaults) -
check_bundles(list[_CheckBundle])
Validators:
-
extension_names_to_mappings→extensions -
propagate_defaults_to_checks -
validate_identifier_consistency -
validate_defaults_apply_to_some_check -
validate_identifier_is_not_a_result_field -
validate_filter_values_complete
extension_names_to_mappings
pydantic-validator
¶
Accept an extension written as its name, e.g. httpfs for {name: httpfs}, and an empty extensions:.
Source code in src/koality/models.py
from_yaml
classmethod
¶
Validate a configuration from YAML text, read as koality run reads it (see load_yaml).
Examples:
Source code in src/koality/models.py
propagate_defaults_to_checks
pydantic-validator
¶
Merge defaults and check_bundle.defaults into each check before validation.
Merge order (later overrides earlier): 1. defaults 2. bundle defaults 3. check-specific values
For the 'filters' dict, a deep merge is performed so that check-level filters override individual filter entries rather than replacing the whole dict.
Source code in src/koality/models.py
validate_defaults_apply_to_some_check
pydantic-validator
¶
Reject a default that none of the checks it covers accepts (e.g. join_columns for CountChecks).
Source code in src/koality/models.py
validate_filter_values_complete
pydantic-validator
¶
Validate that all filters in checks have column and value set.
Filters in defaults can omit column/value (to be set at check level), but after merging, all filters must have both column and value except for identifier-type filters which are allowed to omit a value (used for naming).
Source code in src/koality/models.py
validate_identifier_consistency
pydantic-validator
¶
Validate identifier filter consistency based on identifier_format.
When identifier_format is 'filter_name' or 'column_name', all identifier filters across all checks must have the same filter name or column name respectively, since these are used as result column headers. Also checks that if identifier_format is 'filter_name' or 'column_name', every check has an identifier filter.
Source code in src/koality/models.py
validate_identifier_is_not_a_result_field
pydantic-validator
¶
Validate that a named identifier field doesn't overwrite a fixed result field such as DATE or VALUE.
Source code in src/koality/models.py
DatabaseProvider
dataclass
¶
DatabaseProvider(database_name: str, database_oid: int, path: str, comment: str | None, tags: dict, internal: bool, type: str, readonly: bool, encrypted: bool, cipher: str | None, options: str | None = None)
Data class representing a DuckDB database provider connection.
ExtensionConfig
pydantic-model
¶
Bases: BaseModel
A DuckDB extension to install (if missing) and load before database_setup runs.
In a config, an extension is written as its name (httpfs) or as a mapping with the repository to install it
from ({name: bigquery, repository: community}): a repository name such as core or community, or a URL or
path of a custom repository (a relative path needs a slash, e.g. ./repository, or it is read as a name).
Without a repository, DuckDB's default (core) is used.
Config:
extra:forbid
Fields:
-
name(str) -
repository(str | None)
FilterConfig
pydantic-model
¶
Bases: BaseModel
Configuration for a single filter.
Example
filters:
partition_date:
column: BQ_PARTITIONTIME
value: yesterday-2 # 2 days before yesterday
type: date
shop_id:
column: shopId
value: EC0601
type: identifier
created_at:
column: created_date
value: today+1 # tomorrow
parse_as_date: true # parses date but doesn't count as the "date" filter
revenue:
column: total_revenue
value: 1000
operator: ">="
Attributes:
| Name | Type | Description |
|---|---|---|
column |
str | None
|
The database column name to filter on. |
value |
FilterValue
|
The filter value (can be any type, will be converted to string in SQL). For IN/NOT IN operators, use a list of values. For date filters, supports relative dates like "today", "yesterday", and offsets like "yesterday-2" or "today+1". |
operator |
FilterOperator
|
SQL comparison operator. Defaults to "=" (equality). |
type |
FilterType
|
Filter type - "date" for date filters (used for rolling checks), "identifier" for identifier filters (e.g., shop_id), "other" for regular filters. Only one "date" and one "identifier" type filter is allowed per configuration. When type="date", the value is automatically parsed as a date. |
parse_as_date |
bool
|
If True, the value will be parsed as a date even for type="other". Useful for filters that need date parsing but aren't the primary date filter. |
Config:
extra:forbid
Fields:
-
column(str | None) -
value(FilterValue) -
operator(FilterOperator) -
type(FilterType) -
parse_as_date(bool)
Validators:
validate_operator_value_combination
pydantic-validator
¶
Validate that operator and value type are compatible.
Skips validation when value is None with default operator, as this indicates a partial filter in defaults that will be completed later.
Source code in src/koality/models.py
load_yaml ¶
Parse YAML text as koality reads configurations: safely, with YAML 1.2's booleans and numbers.
Only true/false are booleans; an unquoted yes/no/on/off (e.g. the country code NO) stays text, as does 12:30, and
010 is the number 10 (see _YamlLoader).
Examples:
>>> load_yaml("country: NO\nflag: true\ntime: 12:30\ncode: 010")
{'country': 'NO', 'flag': True, 'time': '12:30', 'code': 10}