octoprint.settings#
This module represents OctoPrint's settings management. Within this module the default settings for the core
application are defined and the instance of the :class:Settings
is held, which offers getter and setter
methods for the raw configuration values as well as various convenience methods to access the paths to base folders
of various types and the configuration file itself.
.. autodata:: default_settings :annotation: = dict(...)
.. autodata:: valid_boolean_trues
.. autofunction:: settings
.. autoclass:: Settings :members: :undoc-members:
default_settings = _config.dict(by_alias=True)
module-attribute
#
The default settings of the core application.
valid_boolean_trues = CaseInsensitiveSet(True, 'true', 'yes', 'y', '1', 1)
module-attribute
#
Values that are considered to be equivalent to the boolean True
value, used for type conversion in various places.
HierarchicalChainMap(*maps)
#
Stores a bunch of nested dictionaries in chain map, allowing queries of nested values work on lower directories. For example:
Example
example_dict = {"a": "a", "b": {"c": "c"}} hcm = HierarchicalChainMap({"b": {"d": "d"}}, example_dict) cm = ChainMap({"b": {"d": "d"}}, example_dict) cm["b"]["d"] 'd' cm["b"]["c"] Traceback (most recent call last): ... KeyError: 'c' hcm.get_by_path(["b", "d"]) 'd' hcm.get_by_path(["b", "c"]) 'c'
all_layers
property
#
A list of all layers in this map. read-only
bottom_map
property
#
The very bottom layer is the default layer
top_map
property
writable
#
This is the layer that is written to
with_config_defaults(config = None, defaults = None)
#
Builds a new map with the following layers: provided config + any intermediary parents + provided defaults + regular defaults
:param config: :param defaults: :return:
Settings(configfile = None, basedir = None, overlays = None)
#
The :class:Settings
class allows managing all of OctoPrint's settings. It takes care of initializing the settings
directory, loading the configuration from config.yaml
, persisting changes to disk etc and provides access
methods for getting and setting specific values from the overall settings structure via paths.
A general word on the concept of paths, since they play an important role in OctoPrint's settings management. A
path is basically a list or tuple consisting of keys to follow down into the settings (which are basically like
a dict
) in order to set or retrieve a specific value (or more than one). For example, for a settings
structure like the following::
serial:
port: "/dev/ttyACM0"
baudrate: 250000
timeout:
communication: 20.0
temperature: 5.0
sdStatus: 1.0
connection: 10.0
server:
host: "0.0.0.0"
port: 5000
the following paths could be used:
========================================== ============================================================================
Path Value
========================================== ============================================================================
["serial", "port"]
::
"/dev/ttyACM0"
["serial", "timeout"]
::
communication: 20.0
temperature: 5.0
sdStatus: 1.0
connection: 10.0
["serial", "timeout", "temperature"]
::
5.0
["server", "port"]
::
5000
========================================== ============================================================================
However, these would be invalid paths: ["key"]
, ["serial", "port", "value"]
, ["server", "host", 3]
.
config
property
#
A view of the local config as stored in config.yaml
Does not support modifications, they will be thrown away silently. If you need to modify anything in the settings, utilize the provided set and remove methods.
last_modified
property
#
Returns:
-
–
(int) The last modification time of the configuration file.
settings(init = False, basedir = None, configfile = None, overlays = None)
#
Factory method for initially constructing and consecutively retrieving the :class:~octoprint.settings.Settings
singleton.
Parameters:
-
init
(
boolean
) –A flag indicating whether this is the initial call to construct the singleton (True) or not (False, default). If this is set to True and the plugin manager has already been initialized, a :class:
ValueError
will be raised. The same will happen if the plugin manager has not yet been initialized and this is set to False. -
basedir
(
str
) –Path of the base directory for all of OctoPrint's settings, log files, uploads etc. If not set the default will be used:
~/.octoprint
on Linux,%APPDATA%/OctoPrint
on Windows and~/Library/Application Support/OctoPrint
on MacOS. -
configfile
(
str
) –Path of the configuration file (
config.yaml
) to work on. If not set the default will be used:<basedir>/config.yaml
forbasedir
as defined above. -
overlays
(
list
) –List of paths to config overlays to put between default settings and config.yaml
Returns:
-
Settings –
The fully initialized :class:
Settings
instance.
Raises:
-
ValueError
–init
is True but settings are already initialized or vice versa.