senxor.settings
SenxorSettings
Bases: BaseSettings
load(path)
classmethod
Load settings from a file, support yaml, toml, json.
load_from_dict(data)
classmethod
Load settings from a dictionary.
loads(fp, filetype='yaml')
classmethod
Load settings from a file-like object or string, specifying the file type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
file-like object or str or bytes
|
A file-like object with a |
required |
|
Literal['yaml', 'toml', 'json']
|
The file type to parse ('yaml', 'toml', or 'json'). Default is 'yaml'. |
'yaml'
|
Returns:
| Type | Description |
|---|---|
dict[str, Profile]
|
A dictionary of profiles loaded from the input, where each key is the profile name
and the value is a |
apply_settings(obj, profiles)
classmethod
Apply settings to a destination object.
loads(fp, filetype='yaml')
Load settings from a file-like object or string, specifying the file type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
file-like object or str or bytes
|
A file-like object with a |
required |
|
Literal['yaml', 'toml', 'json']
|
The file type to parse ('yaml', 'toml', or 'json'). Default is 'yaml'. |
'yaml'
|
Returns:
| Type | Description |
|---|---|
dict[str, Profile]
|
A dictionary of profiles loaded from the input, where each key is the profile name
and the value is a |
Examples:
load(path)
Load settings from a specified file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str or Path
|
The file path to load settings from. Supports YAML, TOML, and JSON formats. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Profile]
|
A dictionary of profiles loaded from the file, where each key is the profile name
and the value is a |
Examples:
>>> settings = load("settings.yaml")
>>> default_setting = settings["default"]
>>> default_setting.name
'default'
>>> default_setting.settings
{'foo': 1, 'bar': 2}
>>> default_setting.when
'foo > 10 and bar < 20'
apply(senxor, settings)
Apply settings to a Senxor object from either a dictionary of profiles or a file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Senxor
|
The Senxor object to which the settings will be applied. |
required |
|
dict[str, Profile] or Profile or str or Path
|
A file path to load settings from, or a dictionary of profiles, or a single profile. |
required |
Examples:
- Apply settings from a file path:
- Apply settings from a dictionary of profiles:
- Apply a single profile: