Skip to content

Configuration Models API

Purpose

This module defines configuration models for RDEToolKit using Pydantic. It provides structured configuration management with type safety, validation, and automatic default value application for system settings and processing configurations.

Key Features

Configuration Data Models

  • System settings management with type safety
  • MultiDataTile settings for error handling
  • Pydantic-based validation and serialization

Type Safety and Validation

  • Automatic type checking and conversion
  • Field validation with descriptive error messages
  • Default value management

src.rdetoolkit.models.config.SystemSettings

Bases: BaseModel

SystemSettings is a configuration model for the RDEtoolkit system settings.

Attributes:

Name Type Description
extended_mode str | None

The mode to run the RDEtoolkit in. Options include 'rdeformat' and 'MultiDataTile'. Default is None.

save_raw bool

Indicates whether to automatically save raw data to the raw directory. Default is False.

save_nonshared_raw bool

Indicates whether to save nonshared raw data. If True, non-shared raw data will be saved. Default is True.

save_thumbnail_image bool

Indicates whether to automatically save the main image to the thumbnail directory. Default is False.

magic_variable bool

A feature where specifying '${filename}' as the data name results in the filename being transcribed as the data name. Default is False.

extended_mode: str | None = Field(default=None, description='The mode to run the RDEtoolkit in. select: rdeformat, MultiDataTile') class-attribute instance-attribute

magic_variable: bool = Field(default=False, description="The feature where specifying '${filename}' as the data name results in the filename being transcribed as the data name.") class-attribute instance-attribute

save_nonshared_raw: bool = Field(default=True, description='Specifies whether to save nonshared raw data. If True, non-shared raw data will be saved.') class-attribute instance-attribute

save_raw: bool = Field(default=False, description='Auto Save raw data to the raw directory') class-attribute instance-attribute

save_thumbnail_image: bool = Field(default=False, description='Auto Save main image to the thumbnail directory') class-attribute instance-attribute

validate_extended_mode(v) classmethod

Validate extended_mode to only allow exact matches for 'rdeformat' and 'MultiDataTile'.


src.rdetoolkit.models.config.MultiDataTileSettings

Bases: BaseModel

ignore_errors: bool = Field(default=False, description='If true, errors encountered during processing will be ignored, and the process will continue without stopping.') class-attribute instance-attribute


src.rdetoolkit.models.config.Config

Bases: BaseModel

The configuration class used in RDEToolKit.

Attributes:

Name Type Description
system SystemSettings

System related settings.

multidata_tile MultiDataTileSettings | None

MultiDataTile related settings.

smarttable SmartTableSettings | None

SmartTable related settings.

excel_invoice ExcelInvoiceSettings | None

ExcelInvoice related settings.

multidata_tile: MultiDataTileSettings | None = Field(default_factory=MultiDataTileSettings, description='MultiDataTile related settings') class-attribute instance-attribute

smarttable: SmartTableSettings | None = Field(default=None, description='SmartTable related settings') class-attribute instance-attribute

system: SystemSettings = Field(default_factory=SystemSettings, description='System related settings') class-attribute instance-attribute


Practical Usage

Basic Configuration Creation

basic_config.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from rdetoolkit.models.config import Config, SystemSettings, MultiDataTileSettings

# Create system settings
system_settings = SystemSettings(
    extended_mode=True,
    save_raw=True,
    save_thumbnail_image=False
)

# Create MultiDataTile settings
multidatatile_settings = MultiDataTileSettings(
    ignore_errors=False
)

# Create complete configuration
config = Config(
    system=system_settings,
    multidatatile=multidatatile_settings
)

print(f"Extended mode: {config.system.extended_mode}")
print(f"Save raw files: {config.system.save_raw}")
print(f"Ignore errors: {config.multidatatile.ignore_errors}")

Configuration from File

config_from_file.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from rdetoolkit.models.config import Config
from rdetoolkit.config import parse_config_file

# Load configuration from file
config = parse_config_file("config.yaml")

# Access configuration values
print(f"System configuration:")
print(f"  Extended mode: {config.system.extended_mode}")
print(f"  Save raw: {config.system.save_raw}")
print(f"  Save thumbnails: {config.system.save_thumbnail_image}")

print(f"MultiDataTile configuration:")
print(f"  Ignore errors: {config.multidatatile.ignore_errors}")

Dynamic Configuration Management

dynamic_config.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from rdetoolkit.models.config import Config
import os

# Create configuration based on environment variables
config_data = {
    "system": {
        "extended_mode": os.getenv("RDE_EXTENDED_MODE", "false").lower() == "true",
        "save_raw": os.getenv("RDE_SAVE_RAW", "true").lower() == "true",
        "save_thumbnail_image": os.getenv("RDE_SAVE_THUMBNAILS", "false").lower() == "true"
    },
    "multidatatile": {
        "ignore_errors": os.getenv("RDE_IGNORE_ERRORS", "false").lower() == "true"
    }
}

# Create configuration object
config = Config(**config_data)

print("Configuration loaded from environment variables:")
print(f"Extended mode: {config.system.extended_mode}")
print(f"Save raw: {config.system.save_raw}")
print(f"Ignore errors: {config.multidatatile.ignore_errors}")