Configuration environment variablesΒΆ

[1]:
from earthkit.data import config

For the rest of this notebook we disable the Configuration autosave so the changes will not be written into our configuration file.

[2]:
config.autosave = False

Each Configuration parameter has a corresponding environment variable (see the full list here). When an environment variable is set, it takes precedence over the settings parameter as the following example demonstrates it.

Assuming no environmental variable is set the value is read form the config file.

[3]:
config.get("url-download-timeout")
[3]:
30

When the environment variable is set get returns its value.

[4]:
%env EARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT=26
env: EARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT=26
[5]:
config.get("url-download-timeout")
[5]:
26

Setting the value generates a warning. The new value is saved into the config file, but get still returns the value of the environment variable.

[6]:
config.set("url-download-timeout", 10)
config.get("url-download-timeout")
/Users/cgr/git/earthkit-data/src/earthkit/data/core/config.py:412: UserWarning: Config option 'url-download-timeout' is also set by environment variable 'EARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT'.The environment variable takes precedence and its value is returned when calling get().
  warnings.warn(msg)
[6]:
26

The env() method gives details about the set environment variables.

[7]:
config.env()
[7]:
{'url-download-timeout': ('EARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT', '26')}

When we dump the configuration the values set via environment variables are clearly indicated.

[8]:
config
[8]:
NameValueDefault
cache-policy'user''off'
check-out-of-date-urlsTrueTrue
download-out-of-date-urlsFalseFalse
grib-file-serialisation-policy'path''path'
grib-handle-cache-size11
grib-handle-policy'cache''cache'
maximum-cache-disk-usage'98%''98%'
maximum-cache-sizeNoneNone
number-of-download-threads55
reader-type-check-bytes6464
temporary-cache-directory-rootNoneNone
temporary-directory-rootNoneNone
url-download-timeoutEARTHKIT_DATA_URL_DOWNLOAD_TIMEOUT='26'
(10)
'30s'
use-grib-metadata-cacheTrueTrue
use-message-position-index-cacheFalseFalse
use-standalone-mars-client-when-availableTrueTrue
user-cache-directory'/var/folders/93/w0p869rx17q98wxk83gn9ys40000gn/T/earthkit-data-cgr''/var/folders/93/w0p869rx17q98wxk83gn9ys40000gn/T/earthkit-data-cgr'
version'0.19.2.dev25+g34e3518fd.d20260302'''
[ ]: