dom_toml.config


Nested configuration parsed from a TOML file.

Attention

This module has the following additional requirements:

attrs>=23.1.0
tomli-w>=1.0.0
typing-extensions>=4.7.1

These can be installed as follows:

python -m pip install dom-toml[config]

New in version 2.2.0.

Classes:

Config()

Configuration parsed from a TOML file.

Functions:

subtable_field(submethod_type)

Attrs field for a nested table.

table_name(name)

Decorator to override the table name on a Config class.

to_kebab_case(value)

Convert the given string into kebab-case.

class Config[source]

Bases: object

Configuration parsed from a TOML file.

Methods:

__eq__(other)

Method generated by attrs for class Config.

__getstate__()

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Method generated by attrs for class Config.

__setstate__(state)

Automatically created by attrs.

from_dict(config)

Construct a Config from a dictionary or TOML table.

from_json(json_string)

Parse a Config from a JSON string.

from_toml(toml_string)

Parse a Config from a TOML string.

to_dict()

Convert a Config to a dictionary.

to_toml()

Convert a Config to a TOML string.

__eq__(other)

Method generated by attrs for class Config.

__getstate__()

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Method generated by attrs for class Config.

__setstate__(state)

Automatically created by attrs.

classmethod from_dict(config)[source]

Construct a Config from a dictionary or TOML table.

Parameters

config (Mapping[str, Any])

Return type

Self

classmethod from_json(json_string)[source]

Parse a Config from a JSON string.

Parameters

json_string (str)

Return type

Self

classmethod from_toml(toml_string)[source]

Parse a Config from a TOML string.

Parameters

toml_string (str)

Return type

Self

to_dict()[source]

Convert a Config to a dictionary.

Return type

Dict[str, Any]

to_toml()[source]

Convert a Config to a TOML string.

Return type

str

subtable_field(submethod_type)[source]

Attrs field for a nested table.

Parameters

submethod_type (Type[~_C]) – The Config for the table.

Return type

~_C

table_name(name)[source]

Decorator to override the table name on a Config class.

Parameters

name (str) – The new table name.

Return type

Callable[[Type[~_C]], Type[~_C]]

New in version 2.3.0.

to_kebab_case(value)[source]

Convert the given string into kebab-case.

Parameters

value (Union[str, Type[Config], Config])

Return type

str

New in version 2.3.0.

_C = TypeVar(_C, bound=Config)

Type:    TypeVar

Invariant TypeVar bound to dom_toml.config.Config.

dom_toml.config.fields


Primitive field types.

Classes:

Boolean(default)

Boolean config field type.

FieldType(default)

Customisable config field type.

Integer(default)

Integer config field type.

Number(default)

Numerical config field type.

String(default)

String config field type.

class Boolean(default: _FT)[source]

Bases: FieldType

Boolean config field type.

Classes:

field_type

alias of bool

field_type

alias of bool

class FieldType(default: _FT)[source]

Bases: Generic[~_FT]

Customisable config field type.

Methods:

field(default)

Construct an attrs field.

on_setattr(inst, attr, value)

Converts values on __setattr__.

validator(inst, attr, value)

Check if a value conforms to this field’s expected datatype.

Attributes:

field_name

String name of the field.

field_type

The Python type of the object.

classmethod field(default)[source]

Construct an attrs field.

Parameters

default (~_FT)

Return type

~_FT

field_name

Type:    str

String name of the field.

field_type

Type:    Type[~_FT]

The Python type of the object.

classmethod on_setattr(inst, attr, value)[source]

Converts values on __setattr__.

This method is called by attrs.

classmethod validator(inst, attr, value)[source]

Check if a value conforms to this field’s expected datatype.

This method is called by attrs.

class Integer(default: _FT)[source]

Bases: FieldType

Integer config field type.

Classes:

field_type

alias of int

field_type

alias of int

class Number(default: _FT)[source]

Bases: FieldType

Numerical config field type.

Classes:

field_type

alias of float

Methods:

validator(inst, attr, value)

Check if a value is a number.

field_type

alias of float

classmethod validator(inst, attr, value)[source]

Check if a value is a number.

This method is called by attrs.

class String(default: _FT)[source]

Bases: FieldType

String config field type.

Classes:

field_type

alias of str

field_type

alias of str

_FT = TypeVar(_FT)

Type:    TypeVar

Invariant TypeVar.