With ecCodes 2.13.0, there is a new Python3 interface based on CFFI (rather than SWIG). This interface is separated into its own package which is available on PyPI (https://pypi.org/project/eccodes/)
Thanks to B-Open for their contribution.
Note: The ecCodes Python 2 interface will be removed in Q1 2023. Users are strongly advised to migrate to Python 3
Installation
The Python module depends on the ecCodes library that must be installed on the system and accessible as a shared library.
To install the Python3 bindings, first install ecCodes as usual and then:
$ pip3 install eccodes
Binary I/O
When opening any BUFR or GRIB files please ensure this happens in binary mode. For example, to open a GRIB file for reading:
f = open('myfields.grib', 'rb')
And for writing:
f = open('myfields.grib', 'wb')
This change in your programs will also work in Python 2, so you can keep the same code regardless of the Python version used. All the examples on the documentation have been updated to reflect this change.
Alternatives
We have also been working on cfgrib, a higher level Python 3 interface to read GRIB data into xarray. Note that the current status of the package is BETA, so it is not currently suitable for production or operational workloads.
The cfgrib package is also used in the Metview's Python Interface, where the power and flexibility of Metview meet all the possibilities of Python 3.