pymetkit#
- Version:
1.21.0
Warning
These documentation pages are a work in progress.
pymetkit is the Python interface to Metkit.
It provides a thin, idiomatic Python layer over the Metkit library installed on
your system, so you can parse and manipulate MARS requests directly from Python
scripts and notebooks.
It exposes the MARS request model as Pythonic objects built on a
pybind11 extension module that binds the
metkit C++ library directly. The interface is organized in three layers:
API — the Pythonic layer:
MarsRequest(a verb plus aMarsSelection),parse_mars_request(), andexpand().pymetkit._internal— locates and loadslibmetkitat import time via findlibs, verifies the runtime version against the build-time version, initialises the bindings, and re-exports the low-level symbols. Internal; not part of the public API.pybind11 bindings — the compiled
pymetkit_bindingsmodule that bindsmetkit::mars::MarsRequestandmetkit::mars::MarsExpansion.
Note
pymetkit supersedes the legacy CFFI-based interface. If you are migrating from
the old package, see Legacy CFFI interface.
Quick start#
from pymetkit import MarsRequest, expand, parse_mars_request
request = MarsRequest(
"retrieve",
{
"class": "od",
"domain": "g",
"date": "-1",
"expver": "0001",
"step": range(0, 13, 6),
},
)
# Expand a single request.
expanded = expand(request)
print(expanded.verb(), dict(expanded))
# Expand a batch. Internal language checks are performed once for the
# whole batch, rather than once per request.
requests = [
MarsRequest("retrieve", {"class": "od", "date": "-1", "param": str(p)})
for p in [129, 130, 131]
]
expanded_batch = expand(requests)
for req in parse_mars_request("retrieve,class=od,date=-1,param=129,step=12"):
print(req.verb(), req["param"])