Welcome to ReadSettings’s documentation!

Easily manage a customized settings file in JSON, YML, YAML or TOML which you can use for storing all of the settings for your application.

class readsettings.ReadSettings(path, ext=None, autosave=True)

Bases: object

Main ReadSettings class.

Parameters
  • path (string) – The settings file to use.

  • ext (string) – Override the file type.

  • autosave (boolean) – Set the autosave behaviour. Default is True.

Raises

ValueError – Invalid file type provided!

>>> data = ReadSettings("settings-test.json")
>>> data["foo"] = "Hello World"
>>> data["foo"]
'Hello World'
autosave(option=None)

Configure autosaving.

Parameters

option (boolean) – The state to set autosave to. If not provided, it will return the current value.

Return type

boolean

Returns

The new autosave state or the current one.

>>> data = ReadSettings("settings-test.json")
>>> data.autosave()
True
>>> data.autosave(False)
False
>>> data.autosave()
False
clear()

Clear the settings.

>>> data = ReadSettings("settings-test.json")
>>> data.clear()
json(value=None)

Get or set the json object of the settings file.

Parameters

value (object) – Optionally set the JSON value instead of getting it.

>>> data = ReadSettings("settings-test.json")
>>> data.json()
{}
>>> data.json({"foo": "bar"})
{'foo': 'bar'}
save()

Force a file save.

>>> data = ReadSettings("settings-test.json")
>>> data["bar"] = "Lorem Ipsum"
>>> data.save()

Indices and tables