Implementation:173TECH Sayn read project
| Knowledge Sources | |
|---|---|
| Domains | Configuration_Management, Validation |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
Concrete tool for reading and validating the project.yaml configuration file provided by the SAYN framework.
Description
The read_project function reads the project.yaml file from the project root directory and returns a validated Project pydantic model instance. The Project model validates required credentials, default database, parameters, presets, autogroups, and database object naming rules (prefix/suffix/override). It also reads task group YAML files from the tasks/ folder via read_groups.
Usage
Use this function during SAYN application startup to parse and validate the project-level configuration. It is called by App.start_app() and provides the foundation for all subsequent configuration steps.
Code Reference
Source Location
- Repository: SAYN
- File:
sayn/core/project.py - Lines: L15-70 (
Projectmodel andread_project), L73-93 (TaskGroupFileandread_groups), L101-178 (get_presets), L208-449 (get_tasks_dict)
Signature
class Project(BaseModel):
required_credentials: List[str]
default_db: Optional[str]
parameters: Optional[Mapping[str, Any]]
presets: Optional[Mapping[str, Mapping[str, Any]]]
autogroups: Mapping[str, Any] = Field(dict(), alias="groups")
database_prefix: Optional[str]
database_suffix: Optional[str]
database_override: Optional[str]
schema_prefix: Optional[str]
schema_suffix: Optional[str]
schema_override: Optional[str]
table_prefix: Optional[str]
table_suffix: Optional[str]
table_override: Optional[str]
class Config:
extra = Extra.forbid
anystr_lower = True
def read_project(project_root: Path = Path(".")) -> Project
def read_groups(project_root: Path = Path(".")) -> Dict[str, TaskGroupFile]
def get_tasks_dict(
global_presets: dict,
groups: dict,
autogroups: dict,
sql_folder: str,
compiler: Compiler,
python_loader: PythonLoader,
) -> Result[Dict]
Import
from sayn.core.project import read_project, read_groups, get_tasks_dict, Project
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| project_root | Path | No | Root directory containing project.yaml (defaults to current directory)
|
| project.yaml | file | Yes | YAML file with required_credentials, default_db, parameters, presets, groups |
Outputs
| Name | Type | Description |
|---|---|---|
| Project | Project (pydantic) | Validated project configuration model |
| groups | Dict[str, TaskGroupFile] | Task group definitions from tasks/*.yaml
|
| tasks_dict | Result[Dict] | Merged task definitions with presets resolved (from get_tasks_dict)
|
Usage Examples
Reading Project Configuration
from sayn.core.project import read_project, read_groups
# Read and validate project.yaml
project = read_project(Path("."))
print(project.required_credentials) # ["warehouse", "api_db"]
print(project.default_db) # "warehouse"
# Read task group files from tasks/ folder
groups = read_groups(Path("."))
for group_name, group in groups.items():
print(f"Group: {group_name}")
if group.tasks:
for task_name, task in group.tasks.items():
print(f" Task: {task_name}")
Building Task Dictionary
from sayn.core.project import get_tasks_dict
from sayn.utils.compiler import Compiler
from sayn.utils.python_loader import PythonLoader
# After reading project and groups
result = get_tasks_dict(
global_presets=project.presets or {},
groups=groups,
autogroups=project.autogroups,
sql_folder="sql",
compiler=compiler,
python_loader=python_loader,
)
if result.is_ok:
tasks = result.value # Dict of task_name -> task definition