archivebox.config.configset

Pydantic-backed config loading for ArchiveBox.

Module Contents

Classes

CaseConfigParser

IniConfigSettingsSource

Custom settings source that reads from ArchiveBox.conf (INI format). Flattens all sections into a single namespace.

BaseConfigSet

Pure typed runtime model for config sections.

Functions

read_ini_config

Read and flatten an ArchiveBox INI config file.

_config_decoder

Return a JSON decoder and the dict/list-typed field names for a config model.

decode_config_inputs

Decode string-only config values once at the boundary to typed config.

Data

COMPUTED_CONFIG_KEYS

_PARSED_INI_CONFIG

API

archivebox.config.configset.COMPUTED_CONFIG_KEYS[source]

(‘TERM_WIDTH’, ‘COMMIT_HASH’, ‘BUILD_TIME’, ‘USES_SUBDOMAIN_ROUTING’, ‘ENABLES_FULL_JS_REPLAY’, ‘CON…

class archivebox.config.configset.CaseConfigParser(defaults=None, dict_type=_default_dict, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=DEFAULTSECT, interpolation=_UNSET, converters=_UNSET)[source]

Bases: configparser.ConfigParser

optionxform(optionstr: str) → str[source]
archivebox.config.configset._PARSED_INI_CONFIG: tuple[pathlib.Path, str, dict[str, Any]] | None[source]

None

archivebox.config.configset.read_ini_config(config_path: str | pathlib.Path) → dict[str, Any][source]

Read and flatten an ArchiveBox INI config file.

class archivebox.config.configset.IniConfigSettingsSource[source]

Bases: pydantic_settings.PydanticBaseSettingsSource

Custom settings source that reads from ArchiveBox.conf (INI format). Flattens all sections into a single namespace.

get_field_value(field: Any, field_name: str) → tuple[Any, str, bool][source]
__call__() → dict[str, Any][source]
_load_config_file() → dict[str, Any][source]
archivebox.config.configset._config_decoder(settings_cls: type[pydantic.BaseModel]) → tuple[archivebox.config.configset.IniConfigSettingsSource, frozenset[str]][source]

Return a JSON decoder and the dict/list-typed field names for a config model.

Both depend only on the class’s fields, which are fixed once the model is built, yet building the source and classifying every annotation cost more than the decoding itself on each get_config() call.

archivebox.config.configset.decode_config_inputs(settings_cls: type[pydantic.BaseModel], config: collections.abc.Mapping[str, Any], *, decode_unknown_json: bool = False) → dict[str, Any][source]

Decode string-only config values once at the boundary to typed config.

class archivebox.config.configset.BaseConfigSet[source]

Bases: pydantic.BaseModel

Pure typed runtime model for config sections.

Source-loading subclasses combine this model with BaseSettings and load:

  1. Environment variables

  2. ArchiveBox.conf file (INI format, flattened)

  3. Default values

Subclasses define fields with defaults and types:

class ShellConfig(BaseConfigSet):
    DEBUG: bool = Field(default=False)
    USE_COLOR: bool = Field(default=True)
model_config[source]

‘SettingsConfigDict(…)’

computed_config_keys: ClassVar[tuple[str, ...]][source]

()

classmethod settings_customise_sources(settings_cls: type[pydantic_settings.BaseSettings], init_settings: pydantic_settings.PydanticBaseSettingsSource, env_settings: pydantic_settings.PydanticBaseSettingsSource, dotenv_settings: pydantic_settings.PydanticBaseSettingsSource, file_secret_settings: pydantic_settings.PydanticBaseSettingsSource) → tuple[pydantic_settings.PydanticBaseSettingsSource, ...][source]

Define the order of settings sources (first = highest priority).

classmethod load_from_file(config_path: pathlib.Path) → dict[str, str][source]

Load config values from INI file.

__getitem__(key: str) → Any[source]
__setitem__(key: str, value: Any) → None[source]
update(*args, **kwargs) → None[source]
__contains__(key: str) → bool[source]
get(key: str, default: Any = None) → Any[source]
as_dict() → dict[str, Any][source]
items()[source]
keys()[source]
values()[source]