Skip to content

senxor.settings

senxor.settings

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 Senxor

The Senxor object to which the settings will be applied.

required
settings 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:

  1. Apply settings from a file path:
>>> apply(senxor, "settings.yaml")
  1. Apply settings from a dictionary of profiles:
>>> settings = load("settings.yaml")
>>> apply(senxor, settings)
  1. Apply a single profile:
>>> profile = load("settings.yaml")["default"]
>>> apply(senxor, profile)

load(path)

Load settings from a specified file path.

Parameters:

Name Type Description Default
path 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 Profile object.

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'

loads(fp, filetype='yaml')

Load settings from a file-like object or string, specifying the file type.

Parameters:

Name Type Description Default
fp file-like object or str or bytes

A file-like object with a .read() method or a string/bytes containing the settings data.

required
filetype 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 Profile object.

Examples:

>>> with open("settings.yaml", "r") as f:
...     settings = loads(f, filetype="yaml")