betty.config module¶
Provide the Configuration API.
- class betty.config.Configurable[source]¶
Bases:
Generic
[ConfigurationT
]Any configurable object.
- Parameters:
args (
typing.Any
)kwargs (
typing.Any
)
- __init__(*args: Any, **kwargs: Any)[source]¶
- Parameters:
args (
typing.Any
)kwargs (
typing.Any
)
- property configuration: ConfigurationT¶
The object’s configuration.
- class betty.config.Configuration[source]¶
Bases:
Dumpable
Any configuration object.
- Parameters:
args (
typing.Any
)kwargs (
typing.Any
)
- __init__(*args: Any, **kwargs: Any)[source]¶
- Parameters:
args (
typing.Any
)kwargs (
typing.Any
)
- classmethod assert_load(configuration: betty.config.ConfigurationT | None = None) Callable[[bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]], betty.config.ConfigurationT] [source]¶
Assert that the dumped configuration can be loaded.
- Parameters:
configuration (
typing.Optional
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)])- Return type:
typing.Callable
[[typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]]],typing.Mapping
[str
,typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]]]]],typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]
- classmethod load(dump: bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump], configuration: Self | None = None) Self [source]¶
Load dumped configuration into a new configuration instance.
- Parameters:
dump (
typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]])configuration (
typing.Optional
[typing.Self
])
- Return type:
typing.Self
- on_change(listener: betty.config.Configuration | collections.abc.Callable[[], None]) None [source]¶
Add an on-change listener.
- Parameters:
listener (
betty.config.Configuration
|collections.abc.Callable
[[],None
])- Return type:
- remove_on_change(listener: betty.config.Configuration | collections.abc.Callable[[], None]) None [source]¶
Remove an on-change listener.
- Parameters:
listener (
betty.config.Configuration
|collections.abc.Callable
[[],None
])- Return type:
- class betty.config.ConfigurationCollection[source]¶
Bases:
Configuration
,Generic
[ConfigurationKeyT
,ConfigurationT
]Any collection of
betty.config.Configuration
values.- Parameters:
configurations (
typing.Optional
[typing.Iterable
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]])
- __init__(configurations: Iterable[betty.config.ConfigurationT] | None = None)[source]¶
- Parameters:
configurations (
typing.Optional
[typing.Iterable
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]])
- append(*configurations: betty.config.ConfigurationT) None [source]¶
Append the given values to the end of the sequence.
- Parameters:
configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- insert(index: int, *configurations: betty.config.ConfigurationT) None [source]¶
Insert the given values at the given index.
- Parameters:
index (
int
)configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))
- Return type:
- keys() Iterator[betty.config.ConfigurationKeyT] [source]¶
Get all keys in this collection.
- Return type:
typing.Iterator
[typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]])]
- move_to_beginning(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) to the beginning of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- move_to_end(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) to the end of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- move_towards_beginning(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) one place towards the beginning of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- move_towards_end(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) one place towards the end of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- prepend(*configurations: betty.config.ConfigurationT) None [source]¶
Prepend the given values to the beginning of the sequence.
- Parameters:
configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- remove(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Remove the given keys from the collection.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- to_index(configuration_key: betty.config.ConfigurationKeyT) int [source]¶
Get the index for the given key.
- Parameters:
configuration_key (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- to_indices(*configuration_keys: betty.config.ConfigurationKeyT) Iterator[int] [source]¶
Get the indices for the given keys.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- to_key(index: int) betty.config.ConfigurationKeyT [source]¶
Get the key for the item at the given index.
- Parameters:
index (
int
)- Return type:
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]])
- to_keys(*indices: int | slice) Iterator[betty.config.ConfigurationKeyT] [source]¶
Get the keys for the items at the given indices.
- Parameters:
- Return type:
typing.Iterator
[typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]])]
- values() Iterator[betty.config.ConfigurationT] [source]¶
Get all values in this collection.
- Return type:
typing.Iterator
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]
- class betty.config.ConfigurationMapping[source]¶
Bases:
ConfigurationCollection
[ConfigurationKeyT
,ConfigurationT
],Generic
[ConfigurationKeyT
,ConfigurationT
]A key-value mapping where values are
betty.config.Configuration
.- Parameters:
configurations (
typing.Optional
[typing.Iterable
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]])
- __init__(configurations: Iterable[betty.config.ConfigurationT] | None = None)[source]¶
- Parameters:
configurations (
typing.Optional
[typing.Iterable
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]])
- append(*configurations: betty.config.ConfigurationT) None [source]¶
Append the given values to the end of the sequence.
- Parameters:
configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- dump() bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | type[betty.serde.dump.Void] [source]¶
Dump this instance to a portable format.
- Return type:
typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]]],typing.Mapping
[str
,typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]]],type
[betty.serde.dump.Void
]]
- insert(index: int, *configurations: betty.config.ConfigurationT) None [source]¶
Insert the given values at the given index.
- Parameters:
index (
int
)configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))
- Return type:
- keys() Iterator[betty.config.ConfigurationKeyT] [source]¶
Get all keys in this collection.
- Return type:
typing.Iterator
[typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]])]
- classmethod load(dump: bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump], configuration: Self | None = None) Self [source]¶
Load dumped configuration into a new configuration instance.
- Parameters:
dump (
typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]])configuration (
typing.Optional
[typing.Self
])
- Return type:
typing.Self
- move_to_beginning(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) to the beginning of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- move_to_end(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) to the end of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- move_towards_beginning(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) one place towards the beginning of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- move_towards_end(*configuration_keys: betty.config.ConfigurationKeyT) None [source]¶
Move the given keys (and their values) one place towards the end of the sequence.
- Parameters:
configuration_keys (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- prepend(*configurations: betty.config.ConfigurationT) None [source]¶
Prepend the given values to the beginning of the sequence.
- Parameters:
configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- replace(*values: betty.config.ConfigurationT) None [source]¶
Replace any existing values with the given ones.
- Parameters:
values (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- to_index(configuration_key: betty.config.ConfigurationKeyT) int [source]¶
Get the index for the given key.
- Parameters:
configuration_key (
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]]))- Return type:
- to_key(index: int) betty.config.ConfigurationKeyT [source]¶
Get the key for the item at the given index.
- Parameters:
index (
int
)- Return type:
typing.TypeVar
(ConfigurationKeyT
, bound=typing.Union
[typing.SupportsIndex
,typing.Hashable
,type
[typing.Any
]])
- update(other: Self) None [source]¶
Update this configuration with the values from
other
.- Parameters:
other (
typing.Self
)- Return type:
- values() Iterator[betty.config.ConfigurationT] [source]¶
Get all values in this collection.
- Return type:
typing.Iterator
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]
- class betty.config.ConfigurationSequence[source]¶
Bases:
ConfigurationCollection
[int
,ConfigurationT
],Generic
[ConfigurationT
]A sequence of configuration values.
- Parameters:
configurations (
typing.Optional
[typing.Iterable
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]])
- __init__(configurations: Iterable[betty.config.ConfigurationT] | None = None)[source]¶
- Parameters:
configurations (
typing.Optional
[typing.Iterable
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]])
- append(*configurations: betty.config.ConfigurationT) None [source]¶
Append the given values to the end of the sequence.
- Parameters:
configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- dump() bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | type[betty.serde.dump.Void] [source]¶
Dump this instance to a portable format.
- Return type:
typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]]],typing.Mapping
[str
,typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]]],type
[betty.serde.dump.Void
]]
- insert(index: int, *configurations: betty.config.ConfigurationT) None [source]¶
Insert the given values at the given index.
- Parameters:
index (
int
)configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))
- Return type:
- classmethod load(dump: bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump], configuration: Self | None = None) Self [source]¶
Load dumped configuration into a new configuration instance.
- Parameters:
dump (
typing.Union
[bool
,int
,float
,str
,None
,typing.Sequence
[Dump],typing.Mapping
[str
, Dump]])configuration (
typing.Optional
[typing.Self
])
- Return type:
typing.Self
- move_to_beginning(*configuration_keys: int) None [source]¶
Move the given keys (and their values) to the beginning of the sequence.
- move_to_end(*configuration_keys: int) None [source]¶
Move the given keys (and their values) to the end of the sequence.
- move_towards_beginning(*configuration_keys: int) None [source]¶
Move the given keys (and their values) one place towards the beginning of the sequence.
- move_towards_end(*configuration_keys: int) None [source]¶
Move the given keys (and their values) one place towards the end of the sequence.
- prepend(*configurations: betty.config.ConfigurationT) None [source]¶
Prepend the given values to the beginning of the sequence.
- Parameters:
configurations (
typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
))- Return type:
- update(other: Self) None [source]¶
Update this configuration with the values from
other
.- Parameters:
other (
typing.Self
)- Return type:
- values() Iterator[betty.config.ConfigurationT] [source]¶
Get all values in this collection.
- Return type:
typing.Iterator
[typing.TypeVar
(ConfigurationT
, bound=betty.config.Configuration
)]
- class betty.config.FileBasedConfiguration[source]¶
Bases:
Configuration
Any configuration that is stored in a file on disk.
- async read(configuration_file_path: pathlib.Path | None = None) None [source]¶
Read the configuration from file.
If a configuration file path is given, it will become this configuration’s new file path, and its contents will be read.
If no configuration file path is given, the previously set file path will be read, if that file exists.
- Parameters:
configuration_file_path (
pathlib.Path
|None
)- Return type:
- async write(configuration_file_path: pathlib.Path | None = None) None [source]¶
Write the configuration to file.
If a configuration file path is given, it will become this configuration’s new file path, and it will be written to.
If no configuration file path is given, the previously set file path will be written to, if that file exists.
- Parameters:
configuration_file_path (
pathlib.Path
|None
)- Return type: