Configuration environment variablesΒΆ

[1]:
from earthkit.geo 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_GEO_URL_DOWNLOAD_TIMEOUT=26
env: EARTHKIT_GEO_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-geo/src/earthkit/geo/utils/config.py:359: UserWarning: Config option 'url-download-timeout' is also set by environment variable 'EARTHKIT_GEO_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_GEO_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''user'
check-out-of-date-urlsFalseFalse
download-out-of-date-urlsFalseFalse
maximum-cache-disk-usageNoneNone
maximum-cache-size'5GB''5GB'
regrid-precomputed-weights-maximum-memory-cache-size'500MB''500MB'
regrid-precomputed-weights-memory-cache-policy'lru''lru'
regrid-precomputed-weights-memory-cache-strict-modeFalseFalse
temporary-cache-directory-rootNoneNone
temporary-directory-rootNoneNone
url-download-timeoutEARTHKIT_GEO_URL_DOWNLOAD_TIMEOUT='26'
(10)
'30s'
user-cache-directory'/Users/cgr/.cache/earthkit-geo''/Users/cgr/.cache/earthkit-geo'
version'1.0.0rc6.dev0+gb3fd7e116.d20260429'''
[ ]: