API Reference
This section provides the detailed API reference for the darca_yaml module.
yaml_utils.py
Utility module for loading, saving, and validating YAML files.
- class darca_yaml.yaml_utils.YamlUtils[source]
Bases:
object
- static load_yaml_file(file_path: str) dict [source]
Load and parse a YAML file.
- Args:
file_path (str): Path to the YAML file.
- Returns:
dict: Parsed YAML content.
- Raises:
YamlUtilsException: On read or parse failure.
- static save_yaml_file(file_path: str, data, validate: bool = False, schema: dict = None) bool [source]
Save data to a YAML file, with optional validation.
- Args:
file_path (str): Path to save YAML file. data (dict or str): Data to be saved. If str, must be valid YAML. validate (bool): Whether to validate the data. schema (dict): Schema used for validation (required if validate=True).
- Returns:
bool: True if file saved successfully.
- Raises:
YamlUtilsException: On validation, serialization, or save failure.
- static validate_yaml(data: dict, schema: dict) bool [source]
Validate YAML content using Cerberus schema.
- Args:
data (dict or str): YAML data to validate. If str, must be valid YAML. schema (dict): Cerberus schema definition.
- Returns:
bool: True if valid.
- Raises:
YamlUtilsException: If validation fails.
- exception darca_yaml.yaml_utils.YamlUtilsException(message, error_code=None, metadata=None, cause=None)[source]
Bases:
DarcaException
Custom exception for YAML utility errors.
- __init__(message, error_code=None, metadata=None, cause=None)[source]
Initialize a DarcaException with detailed information.
- Parameters:
message – Error message (str)
error_code – Custom error code (int or str, optional)
metadata – Additional metadata (dict, optional)
cause – The original exception that caused this error (optional)