Skip to content

generators

Configuration generators package.

This package provides custom generators for pydantic-settings-export to generate configuration files in various formats.

Modules:

  • base

    Shared utilities for configuration generators.

  • json

    JSON configuration file generator.

  • toml

    TOML configuration file generator.

  • yaml

    YAML configuration file generator.

Classes:

Functions:

Classes

JsonGenerator

Bases: AbstractGenerator

Generate JSON configuration files.

Methods:

Functions

generate_single
Python
generate_single(settings_info: SettingsInfoModel, level: int = 1) -> str

Generate JSON format configuration.

Parameters:

  • settings_info (SettingsInfoModel) –

    Settings information model

  • level (int, default: 1 ) –

    Nesting level, by default 1

Returns:

  • str

    Generated JSON content

_parse_value
Python
_parse_value(field: FieldInfoModel) -> Any

Parse field value to appropriate Python type.

Parameters:

  • field (FieldInfoModel) –

    Field information

Returns:

  • Any

    Parsed value

JsonGeneratorSettings pydantic-model

Bases: BaseModel

Configuration for JSON generator.

Show JSON schema:
JSON
{
  "description": "Configuration for JSON generator.\n\nGenerator name: `json`.",
  "properties": {
    "paths": {
      "description": "Output file paths",
      "items": {
        "format": "path",
        "type": "string"
      },
      "title": "Paths",
      "type": "array"
    },
    "indent": {
      "default": 2,
      "description": "JSON indentation spaces",
      "title": "Indent",
      "type": "integer"
    }
  },
  "title": "JsonGeneratorSettings",
  "type": "object"
}

Fields:

Attributes

paths pydantic-field
Python
paths: list[Path]

Output file paths

indent pydantic-field
Python
indent: int = 2

JSON indentation spaces

TomlGenerator

Bases: AbstractGenerator

Generate TOML configuration files.

Methods:

Functions

generate_single
Python
generate_single(settings_info: SettingsInfoModel, level: int = 1) -> str

Generate TOML format configuration.

Parameters:

  • settings_info (SettingsInfoModel) –

    Settings information model

  • level (int, default: 1 ) –

    Nesting level, by default 1

Returns:

  • str

    Generated TOML content

_format_value
Python
_format_value(field: FieldInfoModel) -> str

Format field value for TOML.

Parameters:

  • field (FieldInfoModel) –

    Field information

Returns:

  • str

    Formatted value

_parse_value
Python
_parse_value(field: FieldInfoModel) -> Any

Parse field value to appropriate Python type.

Parameters:

  • field (FieldInfoModel) –

    Field information

Returns:

  • Any

    Parsed value

TomlGeneratorSettings pydantic-model

Bases: BaseModel

Configuration for TOML generator.

Show JSON schema:
JSON
{
  "description": "Configuration for TOML generator.\n\nGenerator name: `toml`.",
  "properties": {
    "paths": {
      "description": "Output file paths",
      "items": {
        "format": "path",
        "type": "string"
      },
      "title": "Paths",
      "type": "array"
    },
    "include_comments": {
      "default": true,
      "description": "Include field descriptions as comments",
      "title": "Include Comments",
      "type": "boolean"
    }
  },
  "title": "TomlGeneratorSettings",
  "type": "object"
}

Fields:

Attributes

paths pydantic-field
Python
paths: list[Path]

Output file paths

include_comments pydantic-field
Python
include_comments: bool = True

Include field descriptions as comments

YamlGenerator

Bases: AbstractGenerator

Generate YAML configuration files.

Methods:

Functions

generate_single
Python
generate_single(settings_info: SettingsInfoModel, level: int = 1) -> str

Generate YAML format configuration.

Parameters:

  • settings_info (SettingsInfoModel) –

    Settings information model

  • level (int, default: 1 ) –

    Nesting level, by default 1

Returns:

  • str

    Generated YAML content

_parse_value
Python
_parse_value(field: FieldInfoModel) -> Any

Parse field value to appropriate Python type.

Parameters:

  • field (FieldInfoModel) –

    Field information

Returns:

  • Any

    Parsed value

YamlGeneratorSettings pydantic-model

Bases: BaseModel

Configuration for YAML generator.

Show JSON schema:
JSON
{
  "description": "Configuration for YAML generator.\n\nGenerator name: `yaml`.",
  "properties": {
    "paths": {
      "description": "Output file paths",
      "items": {
        "format": "path",
        "type": "string"
      },
      "title": "Paths",
      "type": "array"
    },
    "include_comments": {
      "default": true,
      "description": "Include field descriptions as comments",
      "title": "Include Comments",
      "type": "boolean"
    }
  },
  "title": "YamlGeneratorSettings",
  "type": "object"
}

Fields:

Attributes

paths pydantic-field
Python
paths: list[Path]

Output file paths

include_comments pydantic-field
Python
include_comments: bool = True

Include field descriptions as comments

Functions

camel_to_snake

Python
camel_to_snake(name: str) -> str

Convert CamelCase to snake_case.

Parameters:

  • name (str) –

    CamelCase string

Returns:

  • str

    snake_case string