# gluonts.core.settings module¶

## gluonts.core.settings¶

This modules offers a Settings-class, which allows to manage a global context.

The idea is to support a form of dependency injection, where instead of passing a concrete value along the call-chain, it is shared through the settings.

gluonts.env is a Settings.

Example:

from gluonts.core.settings import Settings

class MySettings(Settings):
debug: bool = False

settings = MySettings()

def fn():
if settings.debug:
print("In debug mode.")

with settings._let(debug=True):
# this will print the message
fn()

# no message will be printed
fn()


Another option is to inject the context to a function. This has the advantage, that you can still manually pass values, but use the context as a fallback:

@settings._inject("debug")
def fn(debug):
...

# this will use the value defined in the context
fn()

# but one can still set the value manually
fn(False)


Value access is possible with both getitem (setting[“name”]) and getattr (setting.name). To avoid possible name-conflicts, all methods on Settings use a leading underscore (e.g. settings._let). Consequently, keys are not allowed to start with an underscore.

Settings contains a default-dictionary, which can be set to directly and is used by _declare.

Additionally, it’s possible to declare a type, which is checked using pydantic. Whenever a new value is set, it is type-checked.

class gluonts.core.settings.Dependency(fn, dependencies)[source]

Bases: object

resolve(env)[source]
class gluonts.core.settings.Settings(*args, **kwargs)[source]

Bases: object

gluonts.core.settings.inject(settings, *args, **kwargs)[source]

inject(settings, …) is the same as settings._inject(…).

gluonts.core.settings.let(settings, **kwargs)[source]

let(settings, …) is the same as settings._let(…).