API Documentation

smartsettings

package smartsettings

Smart Settings

Easy to use, flexible and versitile settings. It can be serialized to json format, and even encrypted. The updatable feature makes it suitable for value bindings.

  • Author: Quan Lin
  • License: MIT

Classes

  • SmartSettings — The class of smart settings.

Functions

  • from_string — Load settings from a string.

  • from_file — Load settings from a file.

  • to_string — Store settings to a string.

  • to_file — Store settings to a file.

Attributes

  • UTC_TIME_STRING_FORMAT


smartsettings.smartsettings.SmartSettings

class SmartSettings(**kwargs)

The class of smart settings.

This class can be instantiated directly for settings objects. It also can be subclassed for more specific settings classes.

Equality comparison is defined. Indexing operator is defined for accessing the attributes.

The instance of this class is recursively updatable. The left shift operator << is defined for updating attributes from another instance.

Methods

  • _update_with — Recursively update the attributes with another object of the same type.


smartsettings.smartsettings.from_string

function from_string(input_string: str, crypto_key: str | None = None, **kwargs)object

Load settings from a string.

Parameters

  • input_string : str — The input string to load settings from.

  • crypto_key : str | None — The optional decryption key if the string is encrypted.

  • kwargs — Other kwargs to jsonpickle.decode.

Returns

  • object — A settings object.


smartsettings.smartsettings.from_file

function from_file(path: Path | str, crypto_key: str | None = None, default_settings: object = None, **kwargs)object

Load settings from a file.

Parameters

  • path : Path | str — The path of the input file.

  • crypto_key : str | None — The optional decryption key if the file is encrypted.

  • default_settings : object — The default settings to return if the file does not exist.

  • kwargs — Other kwargs to jsonpickle.decode.

Returns

  • object — A settings object.


smartsettings.smartsettings.to_string

function to_string(settings, crypto_key: str | None = None, **kwargs)str

Store settings to a string.

Parameters

  • settings — The settings to be stored.

  • crypto_key : str | None — The optional encryption key.

  • kwargs — Other kwargs to jsonpickle.encode.

Returns

  • str — A string that represents the settings.


smartsettings.smartsettings.to_file

function to_file(settings, path: Path | str, crypto_key: str | None = None, backup_num: int | None = None, **kwargs)

Store settings to a file.

Parameters

  • settings — The settings to be stored.

  • path : Path | str — The path of the output file.

  • crypto_key : str | None — The optional encryption key.

  • backup_num : int | None — The number of backup files to keep.

  • kwargs — Other kwargs to jsonpickle.encode.