pymetkit#

Version:

1.19.2

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 a MarsSelection) and parse_mars_request().

  • pymetkit._internal — glue that locates and loads libmetkit via findlibs, initialises the bindings, and re-exports the raw symbols. Not intended for direct use.

  • pybind11 bindings — the compiled pymetkit_bindings module that binds metkit::mars::MarsRequest and metkit::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, parse_mars_request

request = MarsRequest(
    "retrieve",
    {
        "class": "od",
        "domain": "g",
        "date": "-1",
        "expver": "0001",
        "step": range(0, 13, 6),
    },
)

expanded = request.expand()
print(expanded.verb(), dict(expanded))

for req in parse_mars_request("retrieve,class=od,date=-1,param=129,step=12"):
    print(req.verb(), req["param"])