Config

Manage configuration.

class Config(settings: AppSettings, args: bool = True, config_file: str = '/home/runner/.config/visiomatic/visiomatic.conf')[source]

Bases: object

Manage application settings in groups.

Settings are stored as Pydantic fields.

grouped_dict() dict[source]

Return a dictionary of all settings, organized in groups.

Returns:

gdict (dict) -- Dictionary of settings.

flat_dict() dict[source]

Return a flattened dictionary of all settings.

Returns:

fdict (dict) -- Dictionary of settings.

schema() dict[source]

Return a schema of the settings as a dictionary.

Returns:

schema (dict) -- Schema of the settings, as a dictionary.

schema_json(indent=2) str[source]

Return a schema of the settings as a JSON string.

Parameters:

indent (int) -- Number of indentation spaces.

Returns:

schema (str) -- JSON schema of the settings.

parse_args() dict[source]

Return a dictionary of all settings, with values updated from the command line.

Extra settings are ignored.

Returns:

gdict (dict) -- Dictionary of all settings, organized in groups.

parse_config(filename: str) dict[source]

Return a dictionary of all settings, with values updated from a configuration file in INI format.

Extra settings are ignored.

Parameters:

filename (str | Path) -- Configuration filename.

Returns:

gdict (dict) -- Dictionary of all settings, organized in groups.

save_config(filename) None[source]

Save all settings as a configuration file in INI format.

Extra settings are ignored.

Parameters:

filename (str | Path) -- Configuration filename.

update_from_dict(settings_dict) None[source]

Update internal settings based on a dictionary (in groups)

Parameters:

settings_dict (dict) -- Input dictionary.

Group and define Pydantic-compatible fields.

SField(short: str | None = None, **kwargs) Any[source]

Return Pydantic field with augmented JSON schema including a command-line "shortcut" keyword.

Examples

>>> from pydantic_settings import BaseSettings
>>> class Settings(BaseSettings):
...     parameter: float = SField(
...         short='p',
...         description="an arbitrary parameter",
...         default=10.,
...     )
>>> s = Settings(parameter=3.)
>>> s.model_json_schema()
{'additionalProperties': False, 'properties': {'parameter': {'default': 10.0,
'description': 'an arbitrary parameter', 'short': 'p', 'title': 'Parameter',
'type': 'number'}}, 'title': 'Settings', 'type': 'object'}
Parameters:
  • short (str, optional) -- Shortcut for keyword

  • **kwargs -- Additional Field arguments.

Returns:

Pydantic Field with augmented JSON schema.

Configure application.

override(key: str, value: Any) Any[source]

Convenience function that returns the input value unless it is None, in which case the settings value from key is returned.

Examples

>>> from . import override, settings
>>> settings['port'] = 8009
>>> print(f"{override('port', 8080)}")
8080
>>> print(f"{override('port', None)}")
8009
Parameters:
  • key (str) -- Key to settings value.

  • value (Any) -- Input value.

Returns:

value (Any) -- Input value or settings value.