openscm_runner.settings#

Settings handling

Rather than hard-coding constants, configuration can be source from 2 different sources:

  • Environment variables

  • dotenv files

Environment variables are always used in preference to the values in dotenv files.

ConfigLoader#

class ConfigLoader[source]#

Bases: object

Configuration container

Loads a local dotenv file containing configuration. An example of a configuration file is provided in root of the project.

A combination of environment variables and dotenv files can be used as configuration with an existing environment variables overriding a value specified in a dotenv file.

All configuration is case-insensitive.

>>> config = ConfigLoader()
>>> config["VALUE"]
Traceback (most recent call last):
 ...
KeyError: 'VALUE'
>>> config.get("VALUE", "some_default")
'some_default'
get(key, default=None)[source]#

Get value for a given key, falling back to a default value if not present.

Parameters:
  • key (str) – Key

  • default (Any) – Default value returned if no configuration for key is present.

Returns:

Any – Value with key item. If not value is present default is returned.

load_config()[source]#

Load configuration from disk

A dotenv file is attempted to be loaded. The first file named .env in the current directory or any of its parents will read in.

If no dotenv files are found, then

update(conf)[source]#

Update the configuration

If configuration with duplicate keys already exists, then these values will overwrite the existing values.

Parameters:

conf (dict) – Configuration to use to update the config