Settings and options#
Overview#
Wetterdienst keeps two kinds of configuration apart:
Settings (the
Settingsclass) belong to the host: the cache, the network client, the credentials. They are the same for every request a process makes and are read by the providers.Options (the
Optionsclass) belong to a request: how its values come back (shape, units, names, skipping of empty stations) and how far a station may be to be interpolated from. A request takes them asoptions=, so two requests of one process can differ in them.
from wetterdienst import Options, Settings
from wetterdienst.provider.dwd.observation import DwdObservationRequest
request = DwdObservationRequest(
parameters=[("daily", "kl")],
settings=Settings(cache_disable=True), # the host
options=Options(shape="wide"), # this request
)
Both read the environment, and .env, the same way. The variables of the options keep their
WD_TS_ prefix, so WD_TS_SHAPE="wide" sets the shape option as before.
Note
Settings(ts_shape="long") and the other ts_* settings, settings.ts_shape, and a
settings={"ts_shape": "long"} dict were the old way to set what are options now. They are gone, and
Settings refuses them with an error that names the option to pass instead:
options=Options(shape="long") (or options={"shape": "long"}) on the request. The WD_TS_*
variables stay and are read by Options alone.
Settings#
Settings have four layers from which to be sourced:
Settings arguments e.g. Settings(cache_disable=True)
environment variables e.g.
WD_CACHE_DISABLE="true"local .env file in the same folder (same as above)
default arguments set by
wetterdienst
The arguments are overruled in the above order meaning:
Settings argument overrules environmental variable
environment variable overrules .env file
.env file overrules default argument
As from the environment, only the WD_ variables that name a setting are read from .env. Its
other keys, such as another program’s, or a WD_ key that names no setting, such as the misspelt
WD_CACHE_DIABLE, are ignored. A key within a setting, such as WD_AUTH__KNMI, is read as part of
that setting. A keyword to Settings(...) that names no setting is refused, the removed ts_* settings apart.
The following settings are available:
name |
description |
default |
|---|---|---|
cache_disable |
switch off caching |
False |
cache_dir |
set the directory where the cache is stored; where no home directory resolves, the default is a temporary directory per process, removed at exit; a directory that cannot be written is replaced the same way, with one warning |
platform specific / “wetterdienst” |
fsspec_client_kwargs |
pass arguments to fsspec, especially for querying data behind a proxy |
User-Agent header, timeout 30 |
use_certifi |
use certifi certificate bundle instead of system certificates |
False |
auth |
credentials of the providers that need them, each from its own variable, |
none |
restapi_sql |
let REST API and MCP clients filter with |
False |
restapi_max_stations |
the most stations one |
100 |
restapi_max_rows |
the most rows (estimated) of an answer the REST API sends as one body, else a 400; 0 for no limit |
500000 |
restapi_max_stream_rows |
the most rows (estimated) of a streamed answer ( |
10000000 |
restapi_timeout |
seconds a REST API request may take until its answer begins (a stream: between two chunks), else a 504; 0 for none, see Timeout |
60 |
restapi_max_concurrent |
the most requests under |
32 |
restapi_allowed_hosts |
comma-separated |
none |
Python#
You can import and show Settings like
1from wetterdienst import Settings
2
3settings = Settings()
4settings
{"cache_disable": false, "cache_dir": "/home/docs/.cache/wetterdienst", "fsspec_client_kwargs": {"headers": {"User-Agent": "wetterdienst/0.172.0 (Linux)"}, "timeout": 30}, "auth": {"aemet": null, "knmi": null, "metno_frost": null, "ceda": null}, "use_certifi": false, "restapi_sql": false, "restapi_max_stations": 100, "restapi_max_rows": 500000, "restapi_max_stream_rows": 10000000, "restapi_timeout": 60.0, "restapi_max_concurrent": 32, "restapi_allowed_hosts": []}
or modify them for your very own request like
1from wetterdienst import Settings
2
3settings = Settings(cache_disable=True)
4settings
{"cache_disable": true, "cache_dir": "/home/docs/.cache/wetterdienst", "fsspec_client_kwargs": {"headers": {"User-Agent": "wetterdienst/0.172.0 (Linux)"}, "timeout": 30}, "auth": {"aemet": null, "knmi": null, "metno_frost": null, "ceda": null}, "use_certifi": false, "restapi_sql": false, "restapi_max_stations": 100, "restapi_max_rows": 500000, "restapi_max_stream_rows": 10000000, "restapi_timeout": 60.0, "restapi_max_concurrent": 32, "restapi_allowed_hosts": []}
and hand them to a request with settings=, next to the options= described below.
If your system is running behind a proxy e.g., like
here
you may want to use the trust_env setting like
1from wetterdienst import Settings
2
3settings = Settings(fsspec_client_kwargs={"trust_env": True})
4settings
{"cache_disable": false, "cache_dir": "/home/docs/.cache/wetterdienst", "fsspec_client_kwargs": {"headers": {"User-Agent": "wetterdienst/0.172.0 (Linux)"}, "timeout": 30, "trust_env": true}, "auth": {"aemet": null, "knmi": null, "metno_frost": null, "ceda": null}, "use_certifi": false, "restapi_sql": false, "restapi_max_stations": 100, "restapi_max_rows": 500000, "restapi_max_stream_rows": 10000000, "restapi_timeout": 60.0, "restapi_max_concurrent": 32, "restapi_allowed_hosts": []}
to allow requesting through a proxy.
A dict given as fsspec_client_kwargs, as an argument or as WD_FSSPEC_CLIENT_KWARGS, is merged
into the defaults rather than replacing them: the example above keeps the User-Agent header and the
timeout of 30. A key you give wins over the default of the same name, and headers, given as a
dict, is merged the same way, so a header of your own is sent alongside the User-Agent, and a
User-Agent of your own (in any capitalisation) replaces it. Give "timeout": None (null in
the environment variable) to use aiohttp’s own default instead: five minutes for the whole request,
30 seconds to connect. A dict assigned to fsspec_client_kwargs on a Settings object that
already exists is merged the same way.
A number given as timeout in fsspec_client_kwargs (30 by default) is how many seconds a request
may wait before it fails: for a connection (including a free one from the pool), for the first byte
of the answer, or between two bytes of it. It does not limit the request as a whole, so a download
that keeps arriving is not cut off, however long it takes. Eaufrance Hub’Eau ignores whatever
timeout is given and uses 120 seconds, as its service can take longer than 30 seconds to answer.
If you’re experiencing SSL certificate verification issues, especially in corporate environments or when system certificates are outdated, you can enable the certifi certificate bundle:
1from wetterdienst import Settings
2
3settings = Settings(use_certifi=True)
4settings
{"cache_disable": false, "cache_dir": "/home/docs/.cache/wetterdienst", "fsspec_client_kwargs": {"headers": {"User-Agent": "wetterdienst/0.172.0 (Linux)"}, "timeout": 30}, "auth": {"aemet": null, "knmi": null, "metno_frost": null, "ceda": null}, "use_certifi": true, "restapi_sql": false, "restapi_max_stations": 100, "restapi_max_rows": 500000, "restapi_max_stream_rows": 10000000, "restapi_timeout": 60.0, "restapi_max_concurrent": 32, "restapi_allowed_hosts": []}
This uses the certifi package which provides Mozilla’s carefully curated collection of Root Certificates for validating the trustworthiness of SSL certificates while verifying the identity of TLS hosts.
Options#
Options have the same four layers, and the arguments overrule the rest in the same order:
Options arguments e.g.
Options(shape="long"), or a dict of them,options={"shape": "long"}environment variables e.g.
WD_TS_SHAPE="wide"local .env file in the same folder (same as above)
default arguments set by
wetterdienst
A dict names only the options it changes and leaves the rest to the environment and the defaults.
What it names replaces the environment’s value for that option as a whole: a unit_targets dict
is not merged with a WD_TS_UNIT_TARGETS the host sets. Options(...) itself, as Settings(...)
does, merges a mapping it is given with the environment’s key by key; give a dict, or use
options.replace(...), to replace it. A key within an option, such as
WD_TS_UNIT_TARGETS__TEMPERATURE, is read as part of that option, and a keyword to Options(...)
that names no option is refused. As for the settings, only the WD_TS_ variables that name an
option are read from .env.
An Options is frozen. options.replace(shape="wide") gives a changed copy, validated as a new
instance is. A request takes its options when it is built, so build it with the ones you want.
The environment variable of an option is its name in capitals behind WD_TS_, e.g.
WD_TS_GEO_STATION_DISTANCE_HOMOGENEOUS. The following options are available:
name |
description |
default |
|---|---|---|
humanize |
rename parameters to more meaningful names |
True |
shape |
reshape the returned data to a long/tidy format, one of “long”, “wide”; a wide row is one timestamp of one resolution, so resolutions get their own rows while datasets recorded at the same resolution share one, with their parameter names prefixed by the dataset name and the |
“long” |
convert_units |
convert values to target units |
True |
unit_targets |
dictionary of overwrite target units e.g. |
{} |
skip_empty |
skip a station whose requested parameters are covered too sparsely to be worth returning, where too sparsely is defined via |
False |
skip_threshold |
use with |
0.95 |
skip_criteria |
statistical criteria on which the percentage of actual values is calculated with options “min”, “mean”, “max”, where “min” means the percentage of the lowest available parameter is taken, while “mean” takes the average percentage of all parameters and “max” does so for the parameter with the most percentage |
“min” |
drop_nulls |
drop all empty entries thus reducing the workload, requires |
True |
station_window_end_buffer |
how many days after the end its catalogue publishes a station is still kept for the window of a request, the same for every resolution: |
None |
geo_station_distance_homogeneous |
maximum distance (in km) to a station used for interpolation of a homogeneous parameter, one that varies slowly across a region such as air temperature or air pressure |
40.0 |
geo_station_distance_heterogeneous |
the same for a heterogeneous parameter, one that decorrelates within a few tens of kilometres such as precipitation, fresh snow or visibility |
20.0 |
geo_station_distance |
dictionary of per-parameter overrides of the two distances above, e.g. |
{} |
geo_station_distance_resolution_factors |
dictionary of factors the heterogeneous distance is multiplied by, keyed by resolution, e.g. |
{} |
geo_use_nearby_station_distance |
distance to the nearest station which decides whether the data is used directly from this station or if data is being interpolated |
1 |
geo_min_gain_of_value_pairs |
minimum gain of value pairs which decides whether to stop looking for further stations |
0.1 |
geo_num_additional_stations |
number of additional stations to take into account besides gain of value pairs |
3 |
For more on units see the chapter Units, and for the two search radii and their per-parameter overrides the chapter Interpolation & Summary.
Options in Python#
You can import and show the options like
1from wetterdienst import Options
2
3options = Options()
4options
Options(humanize=True, shape='long', convert_units=True, unit_targets={}, skip_empty=False, skip_threshold=0.95, skip_criteria='min', drop_nulls=True, station_window_end_buffer=None, geo_station_distance_homogeneous=40.0, geo_station_distance_heterogeneous=20.0, geo_station_distance={}, geo_station_distance_resolution_factors={}, geo_use_nearby_station_distance=1.0, geo_min_gain_of_value_pairs=0.1, geo_num_additional_stations=3)
or change them for your very own request like
1from wetterdienst import Options
2
3options = Options(shape="wide")
4options.replace(humanize=False)
Options(humanize=False, shape='wide', convert_units=True, unit_targets={}, skip_empty=False, skip_threshold=0.95, skip_criteria='min', drop_nulls=True, station_window_end_buffer=None, geo_station_distance_homogeneous=40.0, geo_station_distance_heterogeneous=20.0, geo_station_distance={}, geo_station_distance_resolution_factors={}, geo_use_nearby_station_distance=1.0, geo_min_gain_of_value_pairs=0.1, geo_num_additional_stations=3)
options.tidy tells whether the shape is long, and options.drop_nulls_effective whether the empty
entries are dropped, which they are in the long shape alone.