pybind11 bindings#
pymetkit_bindings is the compiled pybind11
extension module that binds the metkit C++ classes directly. It is the lowest layer
of PyMetKit and is consumed by pymetkit._internal; the raw MarsRequest
class it exposes is re-exported there as _MarsRequest.
Warning
This is an internal, low-level layer. Application code should use the Pythonic
API (pymetkit.pymetkit.MarsRequest,
pymetkit.pymetkit_type.MarsSelection and
pymetkit.pymetkit.parse_mars_request()) rather than these bindings directly.
The signatures below map one-to-one onto metkit::mars::MarsRequest and are not
covered by the same value-normalization or error-translation guarantees.
The extension is built from src/pymetkit_bindings/bindings.cc and staged into the
wheel as its own top-level package. The shared library libmetkit and its
dependencies must be loaded (via findlibs) before the module is imported, and
init_bindings() must be called once before any other call — both are handled
automatically by pymetkit._internal.
Module-level functions#
- init_bindings()#
Initialise the
eckitruntime (eckit::Main). Must be called once, before any other binding call, whenmetkitis loaded as a shared library from Python.
- version_info()#
Return a list of
(name, version, git_sha1, path)tuples describing everyeckit-registered library currently loaded (e.g.eckit,eccodes,metkit). Used by thepython -m pymetkitdiagnostics CLI.- Return type:
list[tuple[str, str, str, str]]
- parse_marsrequest(string, strict)#
Parse a single MARS request from
string.- Parameters:
string (str) – the MARS request text.
strict (bool) – raise an error (rather than a warning) on invalid values.
- Returns:
the parsed request.
- Return type:
- parse_marsrequests(string, strict)#
Parse one or more MARS requests from
string.- Parameters:
string (str) – text containing one or more MARS requests.
strict (bool) – raise an error (rather than a warning) on invalid values.
- Returns:
the parsed requests.
- Return type:
list[MarsRequest]
Classes#
- class MarsRequest#
A thin binding of
metkit::mars::MarsRequest. Values are passed and returned as lists of strings; no normalization is performed at this layer.- __init__()#
- __init__(verb)
Construct an empty request, or a request with the given
verb.- Parameters:
verb (str) – the request verb (e.g.
"retrieve").
- verb()#
Return the request verb.
- Return type:
str
- set_verb(verb)#
Set the request verb.
- Parameters:
verb (str) – the verb to set.
- set(param, values)#
Set the values of a parameter.
- Parameters:
param (str) – the parameter name.
values (list[str]) – the parameter values.
- has(param)#
Return whether
paramis present in the request.- Parameters:
param (str) – the parameter name.
- Return type:
bool
- params()#
Return the parameter names present in the request.
- Return type:
list[str]
- count_values(param)#
Return the number of values held for
param.- Parameters:
param (str) – the parameter name.
- Return type:
int
- values(param)#
Return the values held for
param.- Parameters:
param (str) – the parameter name.
- Return type:
list[str]
- merge(other)#
Merge
otherinto this request in place: for each shared parameter, the values ofotherthat are not already present are appended (order-preserving union).- Parameters:
other (MarsRequest) – the request to merge in.
- expand(inherit, strict)#
Return the request expanded against the MARS language definition, using
metkit::mars::MarsExpansion.- Parameters:
inherit (bool) – populate the expanded request with default values.
strict (bool) – raise an error (rather than a warning) on invalid values.
- Returns:
the expanded request.
- Return type:
- __repr__()#
Return the request rendered as a MARS request string (
asString()).- Return type:
str