YamlConfigSource#

pydantic model tollan.config.sources.YamlConfigSource[source]#

Configuration source from YAML file.

Examples

>>> import tempfile
>>> with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:
...     _ = f.write("key: value")
...     path = f.name
>>> src = YamlConfigSource(order=0, source=Path(path))
>>> src.format
'yaml'
>>> src.load()
{'key': 'value'}

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Show JSON schema
{
   "title": "YamlConfigSource",
   "description": "Configuration source from YAML file.\n\nExamples\n--------\n>>> import tempfile\n>>> with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:\n...     _ = f.write(\"key: value\")\n...     path = f.name\n>>> src = YamlConfigSource(order=0, source=Path(path))\n>>> src.format\n'yaml'\n>>> src.load()\n{'key': 'value'}",
   "type": "object",
   "properties": {
      "order": {
         "title": "Order",
         "type": "integer"
      },
      "name": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Name"
      },
      "enabled": {
         "default": true,
         "title": "Enabled",
         "type": "boolean"
      },
      "enable_if": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Enable If"
      },
      "format": {
         "const": "yaml",
         "default": "yaml",
         "title": "Format",
         "type": "string"
      },
      "source": {
         "format": "path",
         "title": "Source",
         "type": "string"
      }
   },
   "required": [
      "order",
      "source"
   ]
}

Config:
  • frozen: bool = True

Fields:
Validators:
  • _validate_name » all fields

  • _validate_source » source

field format: Literal['yaml'] = 'yaml'#

Format identifier, always ‘yaml’

Validated by:
  • _validate_name

field source: Path [Required]#

Path to YAML file

Validated by:
  • _validate_name

  • _validate_source

load(context: dict[str, Any] | None = None) DictConfigT[source]#

Load configuration from YAML file.

Parameters:

context (dict[str, Any] | None, optional) – Context dictionary (unused, for signature compatibility)

Returns:

Configuration dictionary

Return type:

dict[str, Any]

Raises: