pymetkit.pymetkit_batch#

Bulk operations over MarsRequest objects.

Functions#

parse_mars_request(→ list[pymetkit.pymetkit.MarsRequest])

Parse one or more MARS requests from a string or file-like object.

expand(→ list[MarsRequest] | MarsRequest)

Expand one or more requests against the MARS language definition.

Module Contents#

parse_mars_request(file_or_str: IO | str, strict: bool = False) list[pymetkit.pymetkit.MarsRequest]#

Parse one or more MARS requests from a string or file-like object.

Parameters:
  • file_or_str (str | IO) – MARS request text, or an open file containing it.

  • strict (bool) – If True, raise on invalid values instead of discarding them.

Returns:

The parsed requests, in the order they appear in the input.

Return type:

list[MarsRequest]

Raises:

MetKitException – If the input cannot be parsed.

expand(mars_requests: list[MarsRequest] | MarsRequest, inherit: bool = True, strict: bool = False) list[MarsRequest] | MarsRequest#

Expand one or more requests against the MARS language definition.

Internal language checks are performed once for the whole batch rather than once per request. Pass a list whenever expanding more than one request.

A single MarsRequest may also be passed directly; the return type matches the input shape.

Parameters:
  • mars_requests (MarsRequest | list[MarsRequest]) – The request or requests to expand.

  • inherit (bool) – If True, populate the result with default values for missing parameters.

  • strict (bool) – If True, raise on invalid values instead of issuing a warning.

Returns:

The expanded request(s). A single input returns a single output.

Return type:

MarsRequest | list[MarsRequest]

Raises:

MetKitException – If a request is incompatible with the MARS language definition.

Examples

>>> requests = [
...     MarsRequest("retrieve", {"class": "od", "date": "-1", "param": "130"}),
...     MarsRequest("retrieve", {"class": "od", "date": "-1", "param": "131"}),
... ]
>>> expanded = expand(requests)
>>> len(expanded)
2