DictConfigSource#

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

Configuration source from dictionary.

Keys can be strings or integers. Integer keys are used by rupdate to update list items at specific indices.

Examples

>>> from tollan.config.sources import ConfigSourceList
>>> sources = ConfigSourceList(
...     data=[
...         {"format": "dict", "source": {"key": "value"}, "order": 1}
...     ]
... )
>>> src = sources[0]
>>> src.format
'dict'
>>> 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": "DictConfigSource",
   "description": "Configuration source from dictionary.\n\nKeys can be strings or integers. Integer keys are used by rupdate\nto update list items at specific indices.\n\nExamples\n--------\n>>> from tollan.config.sources import ConfigSourceList\n>>> sources = ConfigSourceList(\n...     data=[\n...         {\"format\": \"dict\", \"source\": {\"key\": \"value\"}, \"order\": 1}\n...     ]\n... )\n>>> src = sources[0]\n>>> src.format\n'dict'\n>>> src.load()['key']\n'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": "dict",
         "default": "dict",
         "title": "Format",
         "type": "string"
      },
      "source": {
         "additionalProperties": true,
         "type": "object"
      }
   },
   "required": [
      "order",
      "source"
   ]
}

Config:
  • frozen: bool = True

Fields:
field format: Literal['dict'] = 'dict'#

Format identifier, always ‘dict’

field source: Annotated[DictConfigT, WithJsonSchema({'type': 'object', 'additionalProperties': True})] [Required]#

Dictionary containing configuration data

Constraints:
  • json_schema = {‘type’: ‘object’, ‘additionalProperties’: True}

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

Load configuration from dictionary.

Parameters:

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

Returns:

Deep copy of source dictionary

Return type:

DictConfigT

Raises:

ValueError – If source is not enabled for context